Jump to content
AlienStar

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

Recommended Posts

AlienStar

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

Share this post


Link to post
Share on other sites
Danp2

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")

 

Share this post


Link to post
Share on other sites
AlienStar
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

Share this post


Link to post
Share on other sites
Danp2
8 minutes ago, AlienStar said:

my friend it doesn't work

It doesn't focus the field as you desire. However, it does run without error, which is better than where you started. ;)

You haven't explained your end goal. Are you just wanting to automate the Twitter login?

Share this post


Link to post
Share on other sites
Danp2

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)

 

  • Like 1

Share this post


Link to post
Share on other sites
AlienStar
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 :)

Share this post


Link to post
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

×