← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #154347]: Wait for this OR that

 

Question #154347 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/154347

    Status: Open => Answered

RaiMan proposed the following answer:
wait(img 1 or img2, 20)

interesting: img1 and img2 are both string objects, that evaluate to
True if used with the operator "or". So this is syntactically correct
(no syntax error), but the result is always img1 - so this is searched
in all cases.

How to solve your problem:

--1. use exists()

--2. use observe()

Since --1. is much easier to implement and I prefer this solution, here
you are:

# img1 and img2 contain valid image filenames
weWait = 20 # max seconds we want to wait
while weWait > 0:
  mImg1 = exists(img1,0) # see comment
  mImg2 = exists(img2,0)
  if mImg1 or mImg2: break # leave the loop if at least one found
  wait(1)
  weWait -= 1 # count down wait time

if not (mImg1 and mImg2):
  print "images did not appear"; exit(1)

if mImg1:
  print "image 1 appeared

if mImg2:
  print "image 2 appeared

--- comment
exists(img,0) does only one search and does not wait the standard 3 seconds, if image is not found. So for timing purposes you can calculate 0.5 seconds for every exists. So in your case it will last about 25 to 30 seconds, if n one of the images appears. So if 20 seconds is what you want, set weWait to an appropriate lower value (e.g. 15).

If you need it more often, pack it in a def().

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.