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

    • 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?
    • dumbledown
      By dumbledown
      Hi,
      I'm new to AutoIt but it looks great.
      I want to get the text from Internet Explorer when hovering the mouse over an image, the statusbargettext function appears to be the way to go.
      When running via a hotkey I return a blank, but the msgbox works. Do you know what I'm doing wrong?
      Thanks
      HotKeySet("!x", "RecordURL") ;wait for ALT-a keystroke While 1 ;loop forever to wait for the keypress Sleep(100) ;no need to kill the CPU WEnd Func RecordURL() #include <MsgBoxConstants.au3> AutoItSetOption("WinTitleMatchMode", 2) Local $sText = StatusbarGetText("Internet Explorer") MsgBox($MB_SYSTEMMODAL, "", "Internet Explorer's status bar says: " & $sText) EndFunc  
       
    • boooooom
      By boooooom
      I'm trying to get the HTML code after executing javascript in IE. Here is my code.
      $url = "http://example.com" $oIE = _IECreate($url) Sleep(3000) ;waiting for executing javascript. But useless. $oFrame = _IEFrameGetCollection($oIE, 0) $sCode &= _IEPropertyGet($oFrame, "innerhtml") & @CRLF Then, I get this error.
      "C:\Program Files (x86)\AutoIt3\Include\IE.au3" (2308) : ==> The requested action with this object has failed.: $oTemp = $oObject.document.body $oTemp = $oObject^ ERROR After executing javascript, when I view source in IE, there are HTML code like below.
      <html> <head> ... </head> <body> ... </body> </html> What should I do?