Dent

How do I write to this form in IE?

2 posts in this topic

#1 ·  Posted (edited)

This is the page with the form I'm trying to write to Tennis Odds Calculator

Username : dent

Password : autoit

Here's my full code:-

#include <IE.au3>

Local $TOCUsername = "dent"
Local $TOCPassword = "autoit"

Local $oIE = _IECreate("http://www.tennisoddscalculator.com/")
If Not IsObj($oIE) Then Exit ConsoleWrite("Error creating instance of IE" & @CRLF)

Local $oIE = _IEAttach("TOC")

_IELoadWait($oIE)

_IENavigate($oIE, "http://www.tennisoddscalculator.com/account/calculator/")

_IELoadWait($oIE)

Local $Page = _IEBodyReadText($oIE)

If StringInStr($Page, "Username or Email") Then
    Local $oUsername = _IEGetObjByName($oIE, "username")
    _IEFormElementSetValue($oUsername, $TOCUsername)
    Local $oPassword = _IEGetObjByName($oIE, "password")
    _IEFormElementSetValue($oPassword, $TOCPassword)
    Local $oClassReturn = $oIE.document.getElementsByClassName("form-actions")
    If Not IsObj($oClassReturn) Then Exit ConsoleWrite("Error in $oClassReturn" & @CRLF)
    Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("button")
    If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF)
    $oTagReturn.Item(0).Click()
    _IELoadWait($oIE)
ElseIf StringInStr($Page, "Use the menu at the top") Then
    _IENavigate($oIE, "http://www.tennisoddscalculator.com/account/calculator/")
    _IELoadWait($oIE)
Else
    MsgBox(0, "Error", "Unknown error")
EndIf
Sleep(2000)
Local $oForm = _IEFormGetObjByName($oIE, "form")

Local $sFirstServePc1 = "55.7"
Local $sFirstServePc2 = "54.9"
Local $sFirstServeWonPc1 = "60.0"
Local $sFirstServeWonPc2 = "54.6"
Local $sSecondServeWonPc1 = 72.4"
Local $sSecondServeWonPc2 = "61.0"
Local $sBPSavePc1 = "78.0"
Local $sBPSavePc2 = "68.8"

Local $oPlayer1FSPC = _IEFormElementGetObjByName($oForm, "fs")
$oPlayer1FSPC.Value = $sFirstServePc1
Local $oPlayer2FSPC = _IEFormElementGetObjByName($oForm, "ofs")
$oPlayer2FSPC.Value = $sFirstServePc2
Local $oPlayer1FSWPC = _IEFormElementGetObjByName($oForm, "fsw")
$oPlayer1FSWPC.Value = $sFirstServeWonPc1
Local $oPlayer2FSWPC = _IEFormElementGetObjByName($oForm, "ofsw")
$oPlayer2FSWPC.Value = $sFirstServeWonPc2
Local $oPlayer1SSWPC = _IEFormElementGetObjByName($oForm, "ssw")
$oPlayer1SSWPC.Value = $sSecondServeWonPc1
Local $oPlayer2SSWPC = _IEFormElementGetObjByName($oForm, "ossw")
$oPlayer2SSWPC.Value = $sSecondServeWonPc2
Local $oPlayer1BPS = _IEFormElementGetObjByName($oForm, "kps")
$oPlayer1BPS.Value = $sBPSavePc1
Local $oPlayer2BPS = _IEFormElementGetObjByName($oForm, "kpb")
$oPlayer2BPS.Value = $sBPSavePc2

 

Edited by Dent
I've amended the script so that it only needs to interact with one site and uses hard-coded data

Share this post


Link to post
Share on other sites



#2 ·  Posted

this works for me 

#include <IE.au3>

Local $TOCUsername = "dent"
Local $TOCPassword = "autoit"

Local $oIE = _IECreate("http://www.tennisoddscalculator.com/account/calculator/")

_IELoadWait($oIE)

Local $Page = _IEBodyReadText($oIE)

If StringInStr($Page, "Username or Email") Then
    Local $oUsername = _IEGetObjByName($oIE, "username")
    _IEFormElementSetValue($oUsername, $TOCUsername)
    Local $oPassword = _IEGetObjByName($oIE, "password")
    _IEFormElementSetValue($oPassword, $TOCPassword)
    Local $oClassReturn = $oIE.document.getElementsByClassName("form-actions")
    If Not IsObj($oClassReturn) Then Exit ConsoleWrite("Error in $oClassReturn" & @CRLF)
    Local $oTagReturn = $oClassReturn.Item(0).getElementsByTagName("button")
    If Not IsObj($oTagReturn) Then Exit ConsoleWrite("Error in $oTagReturn" & @CRLF)
    $oTagReturn.Item(0).Click()
    _IELoadWait($oIE)
ElseIf StringInStr($Page, "Use the menu at the top") Then
    _IENavigate($oIE, "http://www.tennisoddscalculator.com/account/calculator/")
    _IELoadWait($oIE)
Else
    MsgBox(0, "Error", "Unknown error")
EndIf
;btn btn-primary
Sleep(2000)
ConsoleWrite("rechied")
Local $sFirstServePc1 = "55.7"
Local $sFirstServePc2 = "54.9"

Local $sFirstServeWonPc1 = "60.0"
Local $sFirstServeWonPc2 = "54.6"

Local $sSecondServeWonPc1 = "72.4"
Local $sSecondServeWonPc2 = "61.0"

Local $sBPSavePc1 = "78.0"
Local $sBPSavePc2 = "68.8"

setValue("fs",$sFirstServePc1)
setValue("fsw",$sFirstServeWonPc1)
setValue("ssw",$sSecondServeWonPc1)

setValue("ofs",$sFirstServePc2)
setValue("ofsw",$sFirstServeWonPc2)
setValue("ossw",$sSecondServeWonPc2)

setValue("kps",$sBPSavePc1)
setValue("kpb",$sBPSavePc2)

$tags = $oIE.document.GetElementsByTagName("button")
For $tag in $tags
    $class_value = $tag.GetAttribute("class")
    If $class_value = "btn btn-primary" Then
        $tag.click()
    EndIf
Next

Func setValue($inputName,$value)
$tags = $oIE.document.GetElementsByTagName("input")
For $tag in $tags
    $class_value = $tag.GetAttribute("name")
    If $class_value = $inputName Then
        $tag.value = $value
    EndIf
Next
EndFunc

 

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

  • Similar Content

    • PunkoHead
      IE function to click on nav button
      By PunkoHead
      Hi all,
      I am having an issue with a website that I want to automate.
      I have this menu and I want to click on the Custom button.

       
       
      The buttons with "inspect element" are: 
       

       
      The code that I tried is
      $sSearch = "Custom" $oFrame = _IEFrameGetObjByName($oIE, "options") $oDivs = _IETagNameGetCollection($oFrame, "ul") For $oDiv In $oDivs If String(_IEPropertyGet($oDiv, "InnerText")) = $sSearch Then _IEAction($oDiv, "click") ExitLoop EndIf Next I also tried with:
      $sMyString = "Custom" Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      However, these are not working. Any ideas?
       
       
    • Dent
      How to download uniquely generated PDF?
      By Dent
      Hi everyone,
      My script uses IE11 on Win7 to log in to a site and enters data into a couple of forms. Upon clicking a link this data is used by the site to generate a PDF report.
      With my current set-up if I do this manually the PDF opens in a new IE tab and I can download or print it. If I right-click the link that creates the PDF and choose Save Target As the PDF is generated and the Open/Save As dialogue at the bottom of the screen opens. All good.
      However I would like the script to automatically download the PDF and close IE and then exit. Closing IE (_IEQuit) and exiting the script are easy enough, but I'm struggling getting the script to download the PDF.
      The link to generate the PDF contains a unique number each time the page with the link is reached, so it's not static. The link position however, using _IELinkGetCollection I can tell the link to generate the PDF is always the 10th one from the end of the page, so using $iNumLinks - 10 I am able to click the link.
      What I believe I need to use is InetGet however the problem I've been facing is that the link isn't static and I haven't worked out a way to access the link by index - is this possible?
      Here is the website HTML for the section containing the link although I don't think it's of much use but it at least shows the format of the link (I can't post a link as it's a password protected area)...
      <div class="rmButton right"><a title="Generates a PDF version of the market report in a new window." href="/rmplus/generatePdf?mr_id=60991" target="_blank">print/save as pdf</a></div> The full link https://www.rightmove.co.uk/rmplus/generatePdf?mr_id=60991 just for completeness - visiting it will give a HTTP 500 unless logged in.
      And here is the code that clicks this link opening the generated PDF in a new tab...
      $oLinks = _IELinkGetCollection($oIE) $iNumLinks = @extended $PrintPDF = _IELinkClickByIndex($oIE, ($iNumLinks - 10)) So, how to use InetGet to visit that link? Or is there a way to Save As the newly opened tab? I've tried _IEAction($oIE, "saveas") but it seems not to work in a tab containing only a PDF.
    • AnAdventurer
      Newbie with a question... or two (IE focused)
      By AnAdventurer
      Hello hello!
      As the title suggests, I am fairly new to AutoIt. In fact, I am new to scripting/coding in general! I've done a few Codecademy courses on CSS and HTML and perhaps Java though this was all a few years back. I've recently come across AutoIt and decided to give it a try since I do quite a few repetitive tasks on a daily basis. In the last couple of weeks I've managed to master (or at least get comfortable with) mouse clicks(left/right), window focus, sending key strokes, controls, and pixel search.
      Now let's get to the topic.
      At this point in time I've tried out a few simple IE scripts but I am having difficulty understanding some things and tying everything together into one tool.
      Specifically, I am struggling with this little bit of code I got from DaleHohm in his IE examples thread. Post #3 (The last example.)
      #include <IE.au3> $sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not) $sWebPage = "http://www.autoitscript.com/forum/index.php?"; webpage with images $oIE = _IECreate() _IENavigate($oIE, $sWebPage) $oIMGs = _IETagNameGetCollection($oIE.document, "img") ; Loop through all IMG tags and save file to local directory using INetGet For $oIMG in $oIMGs $sImgUrl = $oIMG.src $sImgFileName = $oIMG.nameProp INetGet($sImgUrl, $sImgDir & $sImgFileName) Next I have a couple questions about the code above.
      1) ".src" ".nameProp" What are these called? I figured out that I can change the .src to something like .href and it gets anything on the webpage with a .href tag but where can I learn more about these? I still haven't been able to figure out what ".nameProp" is for or what it does. Is there any documentation/list of all the different ".PurpleTextAfterAVariable" (Edit: Not sure why it's red in the above example, just checked SciTE and it's purple there) that I can use?
      2) I understand that the code above gets every "For $oIMG in $oIMGs" on the page but how can I make it only get the first 5? I've tried doing a "count" and a "for" but I am unsure what to replace the "For...in" statement with to keep the script functional. Is there a way to limit the _IETagNameGetCollection function to only get a specific amount of tags?
       
      Finally, the reason I can't just use the code as is.
      The site I am trying to get images from works in this way:
      A href= "Link-To-Picture.jpg" Img src= "Link-To-Picture-thumbnail.jpg" The script above downloads every single thumbnail from the image gallery which is great, it does what it's supposed to but I need the full resolution image.
      After changing the script to get anything with an "A href" tag it does what I need it to do, it gets every single image in full resolution... along with every single one of the 80-100 extra files/links to other sites that are listed under an "A href" tag.
       
      Now I've come up with two solutions but unfortunately, as I mentioned above. I don't know how to put my solution into the code above to make it work.
      Solution 1) Only get the first 5 instances of "A href" on the page.
      As mentioned above. I don't know how to do this.
      Solution 2) Read the entire page, find "-Thumbnail.jpg" replace with ".jpg" and use the script as is.
      I understand how to do a replace. All I am missing is how to do a replace within a field in the code of an IE page. I assume that I have to use the HTMLRead functions but how do I use/alter the data read?
      I really hope all of this make sense and that someone here will be able to help me figure out a solution to my issue or at least answer one of my questions! I do have plenty more questions and I am sure that I'll have even more by the time I figure this out.
      Thank you very much for your time!
    • Juvigy
      IE automation
      By Juvigy
      Hi Guys,
      I have a very complex IE page with lots of Java and Iframes. I need to be able to look for a change in one <input> field. So what i have done is to identify the field and hook an event listener with ObjEvent($title, "_Evt_")  and then i use :
      Func _Evt_OnChange() Local $o_object = @COM_EventObj ConsoleWrite( "Change" & $o_object.value &@CRLF) _FileWriteLine($MainLog, "Change:" & _NOW()) TitleCheck($o_object.value) EndFunc Which work fine user doesn't interact with some of the other buttons or radios on the page. As soon as the user does some interaction or refreshes the page or navigates - the event listener is 'deleted' somehow and no longer works. Any idea how to counteract that? The easiest this is to detect if there is ANY change on the page - then i can identify the INPUT and check for its value. Any idea how to do that ?
    • Dent
      [SOLVED] Possibly used before declaration error in IE.au3
      By Dent
      Hi all,
      So I have a script that interacts with IE but for some reason I can't identify I'm getting the 'possibly used before declaration' error even though I've declared and used those variables.
      Local $oPlayer1FSPC = _IEGetObjByName($oIE, "fs") $oPlayer1FSPC.Value = $sFirstServePc1 Local $oPlayer2FSPC = _IEGetObjByName($oIE, "ofs") $oPlayer2FSPC.Value = $sFirstServePc2 Local $oPlayer1FSWPC = _IEGetObjByName($oIE, "fsw") $oPlayer1FSWPC.Value = $sFirstServeWonPc1 Local $oPlayer2FSWPC = _IEGetObjByName($oIE, "ofsw") $oPlayer2FSWPC.Value = $sFirstServeWonPc2 Local $oPlayer1SSWPC = _IEGetObjByName($oIE, "ssw") $oPlayer1SSWPC.Value = $sSecondServeWonPc1 Local $oPlayer2SSWPC = _IEGetObjByName($oIE, "ossw") $oPlayer2SSWPC.Value = $sSecondServeWonPc2 Local $oPlayer1BPS = _IEGetObjByName($oIE, "kps") $oPlayer1BPS.Value = $sBPSavePc1 Local $oPlayer2BPS = _IEGetObjByName($oIE, "kpb") $oPlayer2BPS.Value = $sBPSavePc2 The $s variables have had strings assigned earlier in the script and I've tested that with ConsoleWrite