Jump to content

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


ThomasQ
 Share

Recommended Posts

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!

$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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

$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...

Edited by ThomasQ
Link to comment
Share on other sites

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? =)

Link to comment
Share on other sites

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...