Dent

Unpredictable results

4 posts in this topic

#1 ·  Posted (edited)

I'm having unpredictable results - rather than post all the code right away (as it's quite lengthy) I've attached an image of the code section in question and an image of the result I'm getting and an image of the result I'm expecting.

As you'll see, box 1 and 2 under Source have the default 'Please select' whereas they should have 'Working Tax Credits' and 'Disability living allowance' in 1 and 2 respectively.

Whilst watching the code run I can see the correct results are being selected but by the time the script finishes executing those boxes have changed back to default.

Here's the site https://www.platform.co.uk/webapp/WEBAPP.EXE?WSYD_EVENT=PW10kkfF

I should mention that if I add in a delay e.g. Sleep(500) then selection remains as expected - but I would rather not do this as it slows the script down.

If $MonthlyUniversalTaxCreditIncomeOne > 0 Then
   $oSelect = _IEGetObjByName($oIE, "AP1AMT1")
   $oSelect.Value = ($MonthlyUniversalTaxCreditIncomeOne * 12)
   $oSelect = _IEGetObjByName($oIE, "OGICMB1A")
   _IEFormElementOptionSelect($oSelect, 8, 1, "byValue")
Else
EndIf

If $MonthlyStateDisabilityIncomeOne > 0 Then
   $oSelect = _IEGetObjByName($oIE, "AP1AMT2")
   $oSelect.Value = ($MonthlyStateDisabilityIncomeOne * 12)
   $oSelect = _IEGetObjByName($oIE, "OGICMB1B")
   _IEFormElementOptionSelect($oSelect, 10, 1, "byValue")
Else
EndIf

Strange result.PNG

Expected result.PNG

Code.PNG

Edited by Dent
Change image for code

Share this post


Link to post
Share on other sites

Please post the code that reproduces that effect, dont need to be everything, just a sample that exemplifies your problem. And avoid to put the code as a image, is much easier to copy and modify than write everything. :)

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok done :)

Hmmm. Just tried running the code again multiple times and it seems to be working every time now? Very strange.

Edited by Dent

Share this post


Link to post
Share on other sites

@Dent Very annoying event, but its not unpredictable. :)

Just do the source first and you will be fine, i also add a event fire that you were forgetting.

Local $oSource1 = _IEGetObjByName($oIE, "OGICMB1A")
If Not IsObj($oSource1) Then Exit ConsoleWrite("Error in $oSource1" & @CRLF)
_IEFormElementOptionSelect($oSource1, 8)

Local $oSource1Ammount = _IEGetObjByName($oIE, "AP1AMT1")
If Not IsObj($oSource1Ammount) Then Exit ConsoleWrite("Error in $oSource1Ammount" & @CRLF)
_IEFormElementSetValue($oSource1Ammount, "800")
$oSource1Ammount.fireEvent("OnBlur")

Local $oSource2 = _IEGetObjByName($oIE, "OGICMB1B")
If Not IsObj($oSource2) Then Exit ConsoleWrite("Error in $oSource2" & @CRLF)
_IEFormElementOptionSelect($oSource2, 10)

Local $oSource2Ammount = _IEGetObjByName($oIE, "AP1AMT2")
If Not IsObj($oSource2Ammount) Then Exit ConsoleWrite("Error in $oSource2Ammount" & @CRLF)
_IEFormElementSetValue($oSource2Ammount, "900")
$oSource2Ammount.fireEvent("OnBlur")

Local $oDateOfBirth_DAY = _IEGetObjByName($oIE, "AP1DAY")
If Not IsObj($oDateOfBirth_DAY) Then Exit ConsoleWrite("Error in $oDateOfBirth_DAY" & @CRLF)
_IEFormElementOptionSelect($oDateOfBirth_DAY, 1)

Local $oDateOfBirth_MONTH = _IEGetObjByName($oIE, "AP1MONTH")
If Not IsObj($oDateOfBirth_MONTH) Then Exit ConsoleWrite("Error in $oDateOfBirth_MONTH" & @CRLF)
_IEFormElementOptionSelect($oDateOfBirth_MONTH, 1)

Local $oDateOfBirth_YEAR = _IEGetObjByName($oIE, "AP1YEAR")
If Not IsObj($oDateOfBirth_YEAR) Then Exit ConsoleWrite("Error in $oDateOfBirth_YEAR" & @CRLF)
_IEFormElementOptionSelect($oDateOfBirth_YEAR, 1990)

Local $oEmploymentStatus = _IEGetObjByName($oIE, "EmpSt1")
If Not IsObj($oEmploymentStatus) Then Exit ConsoleWrite("Error in $oEmploymentStatus" & @CRLF)
_IEFormElementOptionSelect($oEmploymentStatus, "O")

Local $oMainIncome = _IEGetObjByName($oIE, "AFFINC1")
If Not IsObj($oMainIncome) Then Exit ConsoleWrite("Error in $oMainIncome" & @CRLF)
_IEFormElementSetValue($oMainIncome, "5000")
$oMainIncome.fireEvent("OnBlur")

Local $oBonus = _IEGetObjByName($oIE, "PW10kkbA")
If Not IsObj($oBonus) Then Exit ConsoleWrite("Error in $oBonus" & @CRLF)
_IEFormElementSetValue($oBonus, "1200")
$oBonus.fireEvent("OnBlur")

Local $oGender = _IEGetObjByName($oIE, "APP1GDR")
If Not IsObj($oGender) Then Exit ConsoleWrite("Error in $oGender" & @CRLF)
_IEFormElementOptionSelect($oGender, "M")

Local $oJointApplication = _IEGetObjById($oIE, "JointAppN")
If Not IsObj($oJointApplication) Then Exit ConsoleWrite("Error in $oJointApplication" & @CRLF)
_IEAction($oJointApplication, "click")

 

1 person likes this

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

    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • Dent
      By Dent
      As the title says. I open IE11 and navigate to a page with the following HTML5 file upload container in Capture0.JPG
      I want to click Add Files but I haven't been able to. Here's the code that handles the Add Files button in Capture.JPG
      _IEGetObjectById and then using _IEAction to click it doesn't work. I can't give access to the actual page unfortunately because it's password protected.
      All suggestions welcome.


    • milos83
      By milos83
      I have one script that creates _IECreateEmbedded and another script that does _IEAttach.
      I do this because when autoit is doing something, the Embedded IE starts stalling (eg jquery progress animation)
      But there is a new problem.
      When IE is having its own process (like in the example above) any _IE command is slow (in the script that Attaches).
      Here is a comparison of when its in separate and when its in same process:
      Separate process _IETagNameGetCollection : 5000ms
      Separate process _IEAction: 850ms
      Same process _IETagNameGetCollection : 1ms
      Same proccess _IEAction: 135ms
       
      If I try to attach to an embedded IE that is done in c#, I get lightning fast results.
      As you can see, _IE functions work very slow when the embedded IE we are attaching to is made in Autoit.
       
      I did a test and if I empty the WHILE loop in IE process I get these results(but the cpu is at 30% as expected):
      Separate process _IETagNameGetCollection : 33ms
      Separate process _IEAction: 13ms
       
      It slows down if you put anything (like GUIGetMsg) in the WHILE loop.
       
      How do I fix this?
       
      Create IE:
      #include <GUIConstantsEx.au3> #include <IE.au3> #include <WindowsConstants.au3> Local $oIE = _IECreateEmbedded() GUICreate("My Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "http://www.autoitscript.com") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ;takes 1ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ;takes 135ms ConsoleWrite(TimerDiff($timer) & @CRLF) While 1 Local $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd  
      Attach to IE:
      #include <IE.au3> Local $oIE = _IEAttach("My Embedded Web control Test", "embedded") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ; 5000ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ; 850ms ConsoleWrite(TimerDiff($timer) & @CRLF)  
       
      attach.au3
      create.au3
    • Pere
      By Pere
      Hi all,
      I've written the script below to automatically login to a website, in this case infusionsoft.com
      The auto login works fine. Is there a way for me to get errors from Internet explorer, if the login fails because of wrong login credentials. I have searched around, but cannot make sense of this.
      Please forgive me if I have overlooked something simple. I am new to autoit. Please see my script below.
      #include <IE.au3>
      #include <MsgBoxConstants.au3>

      Func AccountAutoLogin()
         ;This line sets the website page to open and inject information
         Global $oIE = _IECreate("https://signin.infusionsoft.com/login")
         ;set the variables to pull the username and password object names
         Local $username = _IEGetObjByName ($oIE, "username")
         Local $password = _IEGetObjByName ($oIE, "password")
         ;set the $oButtons variable to pull all the values of the button class
         Local $oButtons = _IETagnameGetCollection($oIE, "button")
         ;set the username and password values on the login form
         _IEFormElementSetValue ($username, "")
         _IEFormElementSetValue ($password, "")
         ; loop through the button class until we find the text on the login button, then click the button
         For $oButton in $oButtons
            If String($oButton.value) = " Log In " Then $test = $oButtons
               _IEAction($oButton, "click")
               _IELoadWait($oIE)
               if (@error) then MsgBox (0, "Error", @error)
            ExitLoop
         Next
      EndFunc
    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help