AlienStar Posted October 9, 2017 Share Posted October 9, 2017 (edited) 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 October 9, 2017 by AlienStar Link to comment Share on other sites More sharing options...
Danp2 Posted October 9, 2017 Share Posted October 9, 2017 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") Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AlienStar Posted October 9, 2017 Author Share Posted October 9, 2017 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 More sharing options...
Danp2 Posted October 9, 2017 Share Posted October 9, 2017 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? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted October 9, 2017 Share Posted October 9, 2017 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) AlienStar 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AlienStar Posted October 9, 2017 Author Share Posted October 9, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now