Jump to content

set fucus to an element in webpage. no name or id ??


Recommended Posts

hello everybody

I wanna set focus to password field in twitter.com

when view page source I found this :

<div class="LoginForm-input LoginForm-password">
    <input type="password" class="text-input" name="session[password]" placeholder="Password" autocomplete="current-password">
  </div>

so I use this code :

#include <IE.au3>

Local $oIE = _IECreate("https://twitter.com/login?username_or_email=xxxxx")

while _IELoadWait($oIE)=false
    Sleep(100)
wend

Local $ofield = _IEFormGetObjByName($oIE, "session[password]")

_IEAction( $ofield , "focus")

but it failed

please help

Edited by AlienStar
Link to comment
Share on other sites

You are using the wrong command to retrieve an input element. You'll need to get a reference to the form object first using _IEFormGetObjByName. Then you'll using this reference to retrieve the form element using _IEFormElementGetObjByName. Something like this:

#include <IE.au3>

Local $oIE = _IECreate("https://twitter.com/login?username_or_email=xxxxx")

Local $oForm = _IEFormGetObjByName($oIE, 1)
Local $oField  = _IEFormElementGetObjByName($oForm, "session[password]")
_IEAction( $oField , "focus")

 

Link to comment
Share on other sites

57 minutes ago, Danp2 said:

You are using the wrong command to retrieve an input element. You'll need to get a reference to the form object first using _IEFormGetObjByName. Then you'll using this reference to retrieve the form element using _IEFormElementGetObjByName. Something like this:

#include <IE.au3>

Local $oIE = _IECreate("https://twitter.com/login?username_or_email=xxxxx")

Local $oForm = _IEFormGetObjByName($oIE, 1)
Local $oField  = _IEFormElementGetObjByName($oForm, "session[password]")
_IEAction( $oField , "focus")

 

my friend it doesn't work

Link to comment
Share on other sites

Looks like I was grabbing the wrong form. This appears to work for me --

#include <IE.au3>

Local $oIE = _IECreate("https://twitter.com/login")

Local $oForm = _IEFormGetObjByName($oIE, 2)
Local $oField  = _IEFormElementGetObjByName($oForm, "session[username_or_email]")
_IEFormElementSetValue($oField, "xxxxx")
$oField  = _IEFormElementGetObjByName($oForm, "session[password]")
_IEFormElementSetValue($oField, "yyyyy")
_IEFormSubmit($oForm)

 

Link to comment
Share on other sites

3 minutes ago, Danp2 said:

Looks like I was grabbing the wrong form. This appears to work for me --

#include <IE.au3>

Local $oIE = _IECreate("https://twitter.com/login")

Local $oForm = _IEFormGetObjByName($oIE, 2)
Local $oField  = _IEFormElementGetObjByName($oForm, "session[username_or_email]")
_IEFormElementSetValue($oField, "xxxxx")
$oField  = _IEFormElementGetObjByName($oForm, "session[password]")
_IEFormElementSetValue($oField, "yyyyy")
_IEFormSubmit($oForm)

 

thanks so much it works fine :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...