← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #209147]: if exists with try catch

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Your above code does not really make sense.

This is something, that makes sense to test the situation:

if exists(Pattern("file.png'").similar(0.95)):
    getLastMatch().highlight(3) # highlights what exists found
    click(getLastMatch()) # clicks it
else:
   print "image find failed"

This is equivalent, when running in slow motion (blinking red circles
before click):

if exists(Pattern("file.png'").similar(0.95)):
    click(getLastMatch()) # clicks it
else:
   print "image find failed"

To test the match score, just run this one line:

print find("file.png")

This prints the match (if any) and you can see the similarity.

--- stops my execution if the image exists or not
If the above code is the only stuff in your script, then it should either highlight/click the file.png or print "image find failed" in the IDE's message area. 
You might use 
popup("image find failed") instead of the print (but I generally prefer print)

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