Problem using while iteration --- use exists() instead of find()

Asked by Pepe

I did some explamples using sikuli, but when i try to make this one:

while not find(img1.png):
    sleep(1)
    click(img2.png)

click(img1.png)

i can't make it work, if the image is not found i get an error in while line saying that the image is not found, but afaik the script should be like a while True (if the image is not found).
What i'm doing wrong? :S

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

find() cannot be used in this case, since it stops if the image is not found() (see FAQ 1437)

while not exists(img1.png):
    sleep(1)
    click(img2.png)

click(img1.png)

Revision history for this message
RaiMan (raimund-hocke) said :
#2

might help others
FAQ #1437: “How to repeat something in a Sikuli script (make loops)”.

Revision history for this message
Pepe (krane-soke) said :
#3

Thanks for the answer, i was just reading a couple of documentation about sikuli and they use the same instruction that i'm using for doing a facebook app, check this: http://www.slideshare.net/vgod/practical-sikuli-using-screenshots-for-gui-automation-and-testing
I got this url browsing the sikuli source code (i think is in the last commint)

Revision history for this message
Best RaiMan (raimund-hocke) said :
#4

Uuuups, I apologize in the name of the developers: this is an example that is more than one year old (I will tell them ;-)

Things have moved since then ;-)

Today the standard is, that all find() operations stop the script with a FindFailed exception. And there are many more possibilities today - best reading: http://sikuli.org/docx/region.html#exception-findfailed.

exists() was added to the API to manage such decision situation like yours.

Revision history for this message
Pepe (krane-soke) said :
#5

Perfect, at the beggining i thought that my computer was crazy, and i saw that example in another documentation file that i found in one of the reference websites in the main page, i tried to check it today, but it says that the file is now private, so mabye now nobody will have the same problem as i had.
Thanks for your quick answer.

Revision history for this message
Pepe (krane-soke) said :
#6

Perfect, at the beggining i thought that my computer was crazy, and i saw that example in another documentation file that i found in one of the reference websites in the main page, i tried to check it today, but it says that the file is now private, so mabye now nobody will have the same problem as i had.
Thanks for your quick answer.

Revision history for this message
Pepe (krane-soke) said :
#7

Thanks RaiMan, that solved my question.