2

i m applying a sikuli skript on a webpage so that it when page loads it waits for the specific button when it appears it clicks it if not it wait for the certain time until button appears on the webpage..i have done the following script ..it works fine for 2 or three loops but after then the program stops and sikuli window appears ..here is my code.

while exists("img1.png"):

    click("img1.png")
    wait("img2",30*60)
    click("img2.png")
    click("window close button.png") // here it closes the 2nd popup tab after clicking on img2 then it return to its page

where he wait tor the img1 button to appear again .. so wait("img1.png",30*60) //this script works on 3 -4 iteration successfully but then it stops and sikuli window appears with no errors . thanks for your help

3 Answers 3

3

Without any error messages it's hard to tell why your script is not working. But my best guess is that the while exists("img1.png") returns false becouse img1.png can't be found. Maybe Sikuli can't find img1.png because the page has not reloaded yet. Try to add a wait(1) at the end of the while statement.

Alternately try to use the onAppear and observe methods of the Region class: Region.observe()

1

wait("img2",30*60)

Note that this is not the same as wait("img2.png",30*60)

Also, for debugging try find("img2.png") which will hover the mouse over img2.png when it appears on the screen. If the mouse does not hover over img2.png after it appears, you can reduce the accuracy of the search using the similar() command.

1

Not sure wether you solved your problem already.

Effects like yours are always timing problems: something triggered by a mouse action either happens too fast or too slow, so the next Sikuli Script statement does not "see", what your workflow expects to be on the screen.

So as already mentioned by eostrows above, if the script ends silently with no error messages, then the "while exists()" gave a NotFound condition and stopped the loop, because the img1 did not come up within 3 seconds after the click("window close button.png"). This must be so, because all other actions inside the loop either work or end the script with a FindFailed exception.

You could make the workflow more robust this way:

while exists("img1.png", 10): # wait max 10 secs
    click("img1.png")
    click(wait("img2.png",30*60)) # this saves one search for same image
    click("window close button.png")
else:
    print "img1 not seen after window close"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.