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

    • SkysLastChance
      By SkysLastChance
      I am not sure on how to grab the innertext I want. Is there a way I can just grab the second line, or is there a better way to do it all together? 
      #include <IE.au3> $oIE = _IEAttach("Form Details") $oDiv = _IEGetObjById($oIE, "Col3") ;Phone MsgBox (0,"Oops",$oDiv.outertext) When I use this code I get

       


       
      html.au3
    • anthonyjr2
      By anthonyjr2
      I have come across a weird issue that I am not sure how to solve. For some reason, whenever I call WinActivate in certain scenarios instead of opening the single window that already exists, it will create a new blank tab. It should be able to be recreated with this:
      AutoItSetOption("WinTitleMatchMode", 2) Sleep(1000) For $i=0 To 10 WinActivate("Internet Explorer") Next I am not actually doing this in my code, it is just to demonstrate the fact that new tabs keep popping up. Does anyone know why this happens?
       
      EDIT: So I am not sure how reproducible this is, because it only happens every once in a while for me. I will update with more info if I find out anything.
    • SkysLastChance
      By SkysLastChance
      #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate("website") Local $oForms = _IEFormGetCollection($oIE) For $oForm In $oForms MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.name) _IEImgClick($oForm.name, "Reserved.ReportViewerWebControl.axd?OpType=Resource&amp;Version=12.0.5522.0&amp;Name=Microsoft.ReportingServices.Rendering.HtmlRenderer.RendererResources.TogglePlus.gif", "src") Next I am having trouble clicking an image. Here is what I have tried. 

    • SkysLastChance
      By SkysLastChance
      <input name="VsMasterPage$MainContent$LoginUserControl$LoginForm$FormsAuthLoginContainer$LoginButton$InternalButton" class="Button" id="VsMasterPage_MainContent_LoginUserControl_LoginForm_FormsAuthLoginContainer_LoginButton_InternalButton" onclick='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("VsMasterPage$MainContent$LoginUserControl$LoginForm$FormsAuthLoginContainer$LoginButton$InternalButton", "", true, "Login", "", false, false))' type="submit" value="Sign In"> I am trying to click the sign in button on this page. 
      I have tried by class, text, etc 
      Here was my last attempt
      $oButtons = _IETagNameAllGetCollection($o_IE, "button") For $oButton in $oButtons If String($oButton.value) = "Sign In" Then Sleep (1000) _IEAction($oButton, "click") ExitLoop EndIf Next This did not work either.
    • 5ervant
      By 5ervant
      Go create a quick account in Zapier and go to https://zapier.com/app/dashboard and make some Zaps!
      Just need to click the specific instance of an .open-menu button and then click its a.run (anchor) element.
      Doing this IE.au3 script just causing to click its container element:
      $target = 1; Target the first instance #include <IE.au3> $oIE = _IEAttach("Dashboard - Zapier") $count = 0; $tags = _IETagNameGetCollection($oIE, "div") For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "open-menu" Then $count += 1 if $count = $target Then MsgBox(0, "Instance: ", $count) ; $tag.fireEvent("onmousedown") ; _IEAction($tag, "click") ; $tag.fireEvent("onmouseup") ; Or this but not working ; $tag.Click EndIf EndIf Next I also tried to do it using FF.au3
      $target = 1; Target the first instance #Include <Array.au3> #Include <FF.au3> $count = 0; If _FFConnect(Default, Default, 3000) Then $aArray = _FFXPath( "//div[@class='open-menu']", "", 7 ) ; _ArrayDisplay($aArray) For $tag in $aArray $count += 1 if $count = $target Then MsgBox(0, "Instance: ", $count) _FFClick($tag) EndIf Next EndIf Error: _FFClick ==> No match: $sElement: [number]
      Could some help me how to click such buttons on such kind of a dynamic page?