← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #243250]: Multiple if else Problem...

 

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

RaiMan proposed the following answer:
A construction like this only makes sense, if all images mentioned in
the exists() might be visible on the screen with the intention, that the
first match ends the if ... elif ... elif sequence.

So if the second exists() matches, the others will be skipped anyway. It is not something like a switch/case construct.
(elif in Python is only a shortcut to avoid additional indent with the next if)

So the question is: Is that your intention?

If it is, then you should use it like this (with version 1.0.1):
if exists("Wl.png", 0):
          hover()
          click("1390901431169-1.png")
 elif exists("1391427379709.png", 0):
          hover()
          click("1390901695089.png", 0)
 elif exists("1391402658828.png"):
          hover()
          click("4.png")
 elif exists("1390903477117.png"0):
          hover()
          click("1390903521525.png")
 elif exists("1391424371172.png", 0):
          hover()
          click("1391424719725.png")

-- exists(..., 0)
this returns after the first trial (found or not), in your case every exists lasts 3 seconds if not found, so the whole sequence if nothing is found lasts 15+ seconds.
So with your version the final click in the possible 5th elif would happen after about 20 seconds.
with the above optimised version possibly after less than 5 seconds.

-- hover()
is a shortcut for hover(getLastMatch) which avoids an additional search for the same image, that just was found.

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