Sign in to follow this  
Followers 0
adamchapman

IE Form value clears when clicked

2 posts in this topic

I'm trying to make an auto-login script for betfair.com.

In the code below I've read and printed out the id of each form element - this helped me find the username and password fields.

#include<IE.au3>

$oIE = _IECreate("http://www.betfair.com/exchange")

$oForms = _IEFormGetCollection($oIE)
$formcount = 0;

For $oForm In $oForms
  
   $formcount = $formcount+1
   $newID = $oForm.id
   ConsoleWrite(@CRLF & 'formcount = ' & $formcount & @CRLF)
   ConsoleWrite('New ID = ' & $newID & @CRLF)
  
   If $formcount = 2 Then ; login form is the 2nd form on the webpage
      Local $oQuery = _IEFormElementGetCollection($oForm, -1)
      $elementcount = 0
      
      For $oQuery2 In $oQuery ; read through the ogin form
         
         ; print details of each element of form
         $elementcount = $elementcount + 1
         ConsoleWrite('$elementcount = ' & $elementcount & @CRLF)
         $a = _IEFormElementGetValue( $oQuery2 )
         ConsoleWrite('$a = ' & $a & @CRLF)

         If $elementcount = 4 Then ; username field
            _IEFormElementSetValue( $oQuery2  ,"MYUSER")

         EndIf
         
         If $elementcount = 6 Then ; password field
            _IEFormElementSetValue( $oQuery2  ,"MYPASS")
         EndIf

      Next

   EndIf
   
Next

However, after the script has run, if I click on the "password" field in the webpage, the string "MYPASS" disappears. Does this mean I didn't set the form element value correctly?

The html code for the form is a bit complex, perhaps someone can see something in it that I don't understand well enough to spot.
 

Share this post


Link to post
Share on other sites



My mistake, the password field was actually 5 not 6. 

Hope this helps any future-folk reading this. Future!

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Omnitica
      By Omnitica
      Hello!
      I'm new to the forums! Couldn't find any threads covering this issue. Sorry if I'm wrong.

      I'm having problems changing the text/value of a input box. The particular box doesn't have a name or id, just: class="jq_hotkeys_enabled form-control".
      This class appears multiple times throughout the source, so I don't think It's right to reference that object. 
      See image 1.
      However, I've managed to find a object with the name "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" which contains the value of the input box, and the id for the person in the dropdown/combobox left of it. (with "dummy-1" selected).
      See image 2.
      As you can see the value is 3982,4545     ( name , time )
      But when I try to change the value of it by doing:
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") The box doesn't get its new value. I  can see in the source that it's changed though.
      See image 3.
       
      However, if I do: 
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") $oIE.document.parentwindow.execScript("theForm.submit()") ; But it needs to reload the page The box gets its new value after the page reloads by the theForm.submit() function. 
      This is a bit unfortunate as I want the changes to happen instantly like when I type in the box with the keyboard... or select in the combobox.
      Maybe someone knows how I can do this? Looking forward to an answer! 
      Thanks in advance.
       
      Note: Unfortunately I can't provide with the real URL as it is constricted to employees in the company I work for, but let me know If I should provide anything else.
       



    • talkfoodtalk
      By talkfoodtalk
      HI,   I cannot work out how to connect to the input box on this link:   https://cms.bskyb.2wire.com/manage/login   My usual method is in my code but it does not seem to find the elements I need to connect with. I can see that "text" and "password" are on the page but im confused about putting input to it.   Can someone point me in the right direction?         Kind Regards Dave #include <IE.au3> #include <MsgBoxConstants.au3> $PACE = _IEAttach("https://cms.bskyb.2wire.com/manage/login", "url") If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "PACE not attached") $PACE =_IECreate("https://cms.bskyb.2wire.com/manage/login") EndIf $colForms = _IEFormGetCollection ($PACE ) For $oForm In $colForms $colElements = _IETagNameAllGetCollection ( $oForm ) For $oElement In $colElements If StringInStr ( $oElement.getAttribute ( "tkPid", 2 ), "PID19" ) <> 0 Then MsgBox(0, "Result", "Success") _IEFormElementSetValue($oElement, "username") ;~ _IEAction ( $oElement, "click" ) Else EndIf If StringInStr ( $oElement.getAttribute ( "__eventBits=", 2 ), "7409" ) <> 0 Then MsgBox(0, "Result", "Success") _IEFormElementSetValue($oElement, "password") ;~ _IEAction ( $oElement, "click" ) Else EndIf Next Next Local $oInputs = _IETagNameGetCollection($PACE, "input") Local $sTxt = "" For $oInput In $oInputs $sTxt &= $oInput.type & @CRLF if $oInput.type = "text" Then EndIf Next MsgBox($MB_SYSTEMMODAL, "Form Inqput Type", "Form: " & $oInput.form.name & @CRLF & @CRLF & " Types :" & @CRLF & $sTxt)    
    • kalel69
      By kalel69
      Hi Folks.  Looking for a little assistance to help login to one of my company's application's web pages.  These are Intranet based pages, and not open to the general public, and I will try to provide the code and screen shots where I can.  I have been attempting to get this login script to work for quite some time.  Any help would be appreciated. 
      I have 3 types of issues here.
      1.  using the basic _IEFormElementSetValue, instead of replacing the grayed out verbiage (user name) with an un-grayed out text (actual user name in black type font), it does enter the user name, but it is entered still as grayed out text in the input box.
      2.  to get the above to work, i've replaced using _IEFormElementSetValue and instead use an "_IEAction" (2 actually - focus / select all) then a "send" to manually put in the username.  This works upon initial launch of the page, but when logged out, and logging back in, the IEactiion and send fail to enter the fields.
      3.  My company has an .hta application that launches a reporting app, but the page is designed exactly the same as the web page, (except the app contains the code - the .hta app), but it is still the exact same fields defined.  Theoretically knowing the input boxes names as I do and that they're the same, I should be able to log into this app the same way.  However, I can not.  I once contacted dale through email to question why the .hta app would not respond, and he gave me some ideas, and stated if I still have issues, to post a topic here.  so this is what I'm doing, because I still have issues with the .hta app.  And I've also tried to attach to the .hta application as an embedded application, but still could not get the fields to populate (log in screen).
      I have attached screen shots of the intial view of the sign on page, and the view of an attempted signon using _IEFormElementSetValue.
      Here is my code to attempt to attach / launch-create the web page.
      Func _LaunchAdminApp () If $CurServNam= "" Then Return If WinExists("PCDS :: Management") Then Return Local $FTMAddress= "https://"&$CurServNam&"/admin" If NOT WinExists("Fluency for Imaging Log On") Then Local $oIE = _IECreate($FTMAddress) Else Local $oIEWhnd = WinGetHandle("Fluency for Imaging Log On") Local $oIE = _IEAttach($oIEWhnd) EndIf Local $Count = 0 If $AdmAutoLogin = 1 Then If $LoginIDAA = "" Then Return Do $Count+=1 Sleep(100) If $Count > 30 Then MsgBox(0,"Sorry","Can't sign in to Admin App!") Return EndIf Until IsObj($oIE) Local $oForm = _IEFormGetCollection($oIE,0) $Count = 0 Do $Count+=1 Sleep(100) If $Count > 30 Then MsgBox(0,"Sorry","Can't sign in to Admin App!")5 Return EndIf Until IsObj($oForm) WinActivate($oIE) Local $oQueryUser= _IEFormElementGetObjByName ($oForm, "UserName" ) Local $oQueryPW = _IEFormElementGetObjByName ($oForm, "PasswordDisplay") Local $CompID = _IEFormElementGetObjByName ($oForm, "Domain" ) Local $oSubmit = _IEFormElementGetObjByName ($oForm, "loginBtn" ) Sleep(500) ;_IEAction ($oQueryUser,"focus" ) ;_IEAction ($oQueryUser,"selectall" ) ; Send ($LoginIDAA );this will work only for initial login, not for subsequent log in's after logoff. _IEFormElementSetValue ($oQueryUser, $LoginIDAA );this does not work. enters name in gray text, app does not think its there, but can see it. ;_IEAction ($oQueryPW, "focus" ) ;_IEAction ($oQueryPW, "selectall" ) ; Send ($PasswordAA );this will work only for initial login, not for subsequent log in's after logoff. _IEFormElementSetValue ($oQueryPW, $PasswordAA );this does not work. enters password in gray text, app does not think its there, but can see it. _IEFormElementOptionSelect ($CompID,0,1,"byIndex" ) Sleep(5000) If IsObj($oSubmit) Then $oSubmit.click() EndIf If $CloseAfSelAA = 1 Then Exit EndFunc Basically, i'm checking to see if the pages exists first, then either creating a page or attaching to a page depending upon the results of the check.
      I've also attached the source for the signon page for the web app.  Note that the code delivered via the .hta for sign on is exactly the same.
      any and all suggestions are most welcome.  I'm at my witts end here! 
      Thanks in advance!  (I love AutoIT! and this site!)
      view of signon screens.zip
      Company Application Signon Page.html
    • Jewtus
      By Jewtus
      I'm trying to adapt the example
      #include <IE.au3> Local $oIE = _IE_Example("form") Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm") Local $oText = _IEFormElementGetObjByName($oForm, "textExample") _IEFormElementSetValue($oText, "Hey! This works!") to work with a log in page and I'm not sure what I'm doing wrong and why its acting up.
      This is what I tried:
      #include <IE.au3> Local $oIE = _IEAttach("C:\Test.html","Windowtitle") Local $oForm = _IEFormGetObjByName($oIE, "form_auth") Local $oText = _IEFormElementGetObjByName($oForm, "usuario") _IEFormElementSetValue($oText, "Hey! This works!") but it doesn't fill out the form.
      Here is a snippet of the HTML of the form I'm working with:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> <body> <div class="opLogonBody"> <div class="left"> <div class="opLogonComponent"> <div id="auth" class="security"> <form id="form_auth" action="BtoChannelDriver.ssobto?dse_contextRoot=true" method="post" > <div class="body"> <div class="superior"> <fieldset class="identificacion" id="identificacion"><legend>Data</legend> <p>Please enter your logon information and press "Send"</p> <div class="row"><label for="id_1">User:</label><input name="usuario" type="text" id="id_1" maxlength="50" onfocus="idToWrite=&#9;id_1&#9;;pos=null" /></div> <div class="row"><label for="clave">Password:</label><input type="password" name="password" id="clave" maxlength="30" onfocus="idToWrite=&#9;clave&#9;;pos=null"/></div> </fieldset> </div> </div> <div class="foot"><span class="buttons"><input type="submit" value="Send"/></span><span class="link"><a href="" id="id_authenticateLink"></a></span></div> </form> </div> </div> </div> </div> </body> </html> Anyone know why it is not filling out the form?