Jump to content

How do I write to this form in IE?


Dent
 Share

Recommended Posts

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
Link to comment
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

 

Link to comment
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
 Share

×
×
  • Create New...