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



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

    • elbhiri
      By elbhiri
      i have two files a.au3 and b.au3 the both contains the same code which is :
      #include <IE.au3> #include <MsgBoxConstants.au3> Global $myUrl = "https://www.autoitscript.com" RegWrite('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main','SessionMerging','REG_DWORD','00000000') ShellExecute ("iexplore.exe", " -nosessionmerging about:blank") WinWait ("Blank Page") Global $oIE = _IEAttach ("about:blank", "url") _IELoadWait ($oIE) _IENavigate ($oIE, $myUrl) when i launch the both files in the same time two blank windows are opens.
      what im waiting for is that every window navigate to the link but what happen is the first and the second file navigate the url to the same window and the seconde window stay about:blank
      i think the problem happen because i try to open the same url in both windows
      so i need i way to navigate to the same url from two different windows
      Thanks in advance
    • HudsonKane
      By HudsonKane
      I have a page with several hundred <div>s, and each <div> has several hundred child <div>s, each with their own children
      when I use _IETagNameGetCollection($ie, "div", 0) I get them all, but I need to find a way to get say the 3rd child of the 5th child of the second top level <div>
      I have not yet been able to find anything along this line
      Is there any way to determine if an element is a child, parent, sibling?
      Thank you
    • mjolnirmarkiv
      By mjolnirmarkiv
      Hi!
      Does anyone have any idea why Test() returns 0, while Test2() returns 1?
      #include <IE.au3> MsgBox(0, "", Test() & " " & Test2()) Func Test() Local $oHTML = ObjCreate("HTMLFILE") $oHTML.body.innerHTML = FileRead("Test.html") Return IsObj($oHTML.getElementsByClassName("example")) EndFunc Func Test2() Local $oIE = _IEAttach("", "instance", 1) Return IsObj($oIE.document.getElementsByClassName("example")) EndFunc Sample Test.html I open in IE before testing:
      <!DOCTYPE html> <html> <body> <p class="example"></p> <div class="example"></div> </body> </html> I'm receiving html text in a response to http request, I need to parse it fast and easy, getElementsByClassName would have been ideal. I'm using 3.3.12.0 version.
    • ADIN
      By ADIN
      When at some page i access by  IE.au3 appears javascript alert all my code stops and i cant do nothing. Is there any way to stop executing javascript at this page or any way to force autoit to click "OK" when this alert appears?
       
      _IENavigate($oIE, "www.example.com") _IELoadWait($oIE) ; site is loaded and alert appears Send("{ENTER}") ;i want to close alert, this command is not executed, whole script is freeze ; cant do nothing more here....  
    • ADIN
      By ADIN
      I want use _IEFormGetCollection to get form content which was generated by javascript
      Local $oIE = _IECreate("https://www.example.com/login.html") ;Open the login page Local $oSpans = _IETagNameGetCollection($oIE, "span") For $oSpan In $oSpans if $oSpan.innertext == "Login" Then _IEAction($oSpan, "click") EndIf Next ;click span which ganerate by javascript login form Local $oForm = _IEFormGetCollection($oIE, 0) ;get my form, but that was not on website after loading, appears after click button and this function cant see it Local $oEmail = _IEFormElementGetObjByName($oForm, "email") ; trying to parse form but cant _IEFormElementSetValue($oEmail, "example@gmail.com") ; _IEFormGetCollection dont see generated dynamically elements Is here any way to _IETagNameGetCollection read website content again after i inititate a javascript which generate additional content?