Repeat previous step if a image is not found --- use exists() instead of find()

Asked by srijith

So there is game on my Facebook which I'm trying to automate.
So what I need is keep on clicking 2 images ( with a time gap of 2sec).

So lets say img1 and img2 .

Now here img2 appears only if img1 is clicked (img1 is always there)

So I want to click on img1 and then img2 then sleep(2) and then repeat this infinite times .

Now I don't trust this script. What I want is , After clicking img1 if img2 is not found, I want it to repeat click img1 ( click until img2 comes)

This is what I tried with

x=1
while (x < 2):
 while not find(img2):
  click(img1)
 click(img2)
sleep(3)

 But this is not executing just because it says cant find image (img2) at line 3.

But actually if it cant find image, why is the script stopping? doesn't it have to go inside while ?

Question information

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

Ok, Never mind, I made a small change and it worked exactly how I want.

i just replaced "find" with "exists" and it worked. So simple! who knew!!

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

A question:
Since I am currently thinking about some beginners docs and tutorials:
How did you find out, that exists() is the function to use in these cases?