AutoIt Forums: How to make an Infinte Loop, till certain Action has been Performed - AutoIt Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to make an Infinte Loop, till certain Action has been Performed

#1 User is offline   ThomasQ 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 51
  • Joined: 22-July 09

Posted 03 November 2009 - 05:12 PM

Hi all!

This summer I made a scripit to insert data from excel sheets, into a HTML based interface..
Recently, the HTML part has been bugging out, causing a SystemProblem, please try again page. These erros only happen once in a while, at 3 points in the operation: When I click the Publish button, Copy button, or _save button after the Page Done option (see below)..


I need a way for my script to know that if the Error page comes up, it should go back a page, and try the last action again. I know the _IEaction ($oIE, "back") command, but how do I fix the infinite-till-error-has-gone-loop?

Many Thanks in advance!


Quote

$oPublishbutton = _IEFormElementGetObjByName($oForm2, "publish")
_IEAction ($oPublishbutton, "click" )
_IELoadWait ($oIE)
_IELinkClickByText($oIE, "Copy")
_IELoadWait ($oIE)
$oSelectallcopy = _IEGetObjById($oIE, "selectAll")
_IEAction ($oSelectallcopy, "click")
_IELoadWait ($oIE)
$oCopy = _IEGetObjById($oIE, "copy")
_IEAction ($oCopy, "click")
_IELoadWait ($oIE)
_IELinkClickByText($oIE, "<< Back")
_IELoadWait ($oIE)
_IELoadWait ($oIE)
_IELinkClickByText($oIE, "Client Finish")
_IELoadWait ($oIE)
$oAfsluitForm = _IEFormGetObjByName ($oIE, "History")
$oAfsluitselect = _IEFormElementGetObjByName ($oAfsluitForm, "outcome")
_IEFormElementOptionselect ($oAfsluitselect, "Page Done", 1, "byText")
_IELoadWait ($oIE)
$oSaveButton= _IEFormElementGetObjByName($oAfsluitForm, "_save")
_IEAction ($oSaveButton, "click" )
_IELoadWait ($oIE)
_IEQuit($oIE)
_ExcelBookClose ($oExcel)

0

#2 User is offline   middae 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 14
  • Joined: 26-October 09

Posted 03 November 2009 - 05:26 PM

I wrote something similiar a while back. I basically had a structure like this:

Redo:
ie.Navigate/click/whatever PageImSupposedToBeAt
While ie.busy
DoEvents
Wend

If inString(CertainIdentifiableStringAlwaysInAPage,ie.document.innerhtml) = False
GoTo Redo
End if

You might consider keeping a counter in the event it loops so many times it really becomes an infinite loop. I know it's messy, but it worked for tedious things. Or use a while loop, and avoid the GoTo command. Many possibilities.
0

#3 User is offline   lordicast 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 245
  • Joined: 14-August 07
  • Location:SuiSun CA

Posted 03 November 2009 - 05:26 PM

Try the
[ autoIt ]    ( Popup )
;Whatever the command is If @error Then     Dothis() Else     ContinueDoing()  

0

#4 User is offline   ThomasQ 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 51
  • Joined: 22-July 09

Posted 03 November 2009 - 06:28 PM

Thanks for the suggestions!

I'm using autoit3, the Goto/Gosub command are not included in this version, so it has to be a While Loop. I tried the If @error <> 0 Then line, but it did not work for me. It doesn't go back a page, instead it just errors as usual and stops the script.

So here's my code. I'm using the HOME link as an error reference with the $oErrorcheck Array. When this identifies there has been an error, it goes back and tries again, once. Obviously, it has to try again and again, till it succeeds..

How can I fix this using the While Loop?

Thanks in advance!

Quote

$oPublishbutton = _IEFormElementGetObjByName($oForm2, "publish")
_IEAction ($oPublishbutton, "click" )
_IELoadWait ($oIE)



$oErrorCheck = _IELinkGetCollection($oIE)

$oError = ("0")

Local $Array[1]
For $oLink In $oErrorCheck
$klant = _IEPropertyGet($oLink, "innertext")
$HOME = StringInStr($klant, "HOME")
ConsoleWrite($HOME & @CRLF)
If $HOME <> 0 Then
$oError=(+1)
endif
next



If $oError > 0 Then

_IEAction ($oIE, "back")
_IELoadWait ($oIE)
_IEAction ($oPublishbutton, "click" )
_IELoadWait ($oIE)

Endif


_IELinkClickByText($oIE, "Copy)
_IELoadWait ($oIE)
Etc...

This post has been edited by ThomasQ: 03 November 2009 - 06:29 PM

0

#5 User is offline   middae 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 14
  • Joined: 26-October 09

Posted 03 November 2009 - 07:27 PM

I'm gonna use an example in psuedocode -

Page2 = innterhtml has "Second" in it. This is our desired page. It's important that the page you're leaving from does not have "Second" in it. So, find some identifier or even use the address of the page.


$PageText = ""
While instr($PageText,"Second") = 0 ;since $pagetext is empty, this will definitly run at least 1 time.

_IE.button(whatever).click ;assumes we're on page1.

while IE.busy ;waits for IE to finish it's loading of new page.
DoEvents
Wend

$PageText = IE.innerhtml ;set $pagetext for the 'next' while loop to check.
wend

Does that help? =)
0

#6 User is offline   ThomasQ 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 51
  • Joined: 22-July 09

Posted 04 November 2009 - 03:01 AM

Sortof, Thanks!

I've decided to use a Do / Until loop. Just scanning the page text for " System Error has occured", wich sets a counter to 1 if its been found on the page.

It came down like ths


click Publish

Get Body Text form IE
Checktext for "System Error", when it's found set Error Counter to 1, if not, set it to 0
If error counter > 0 then

Do
click Back
click Publish
Get Body Text form IE
Checktext for "System Error", when it's found set Error Counter to 1, if not, set it to 0
Until Error Counter = o
Endif
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users