[HowTo] handling findFailed

Asked by Javier Gonzales Rodriguez on 2020-06-14

Hello there ...

am using Sikuli for pretty basics task, am not a developer so will be great if any of you give me a hand to solve my issue.

So let me explain what am trying to do ...

I have 2 images, if any of them are at the region, then do something "except crashing :( "

I found how to handle it with "exists()" but the problem is that the two images are very very simular with other images so, sometimes it does well, sometimes not, the best is using .. find() but it stop the entire script if does not find anything.

my code is like this...

myRegion = Region(1186,447,173,63)

if myRegion.find(image1.png) or myRegion.find(image2.png):
     print("not found")

continue with the script .....

I tried to handle it with this...
      myRegion = Region(1186,447,173,63)

      if myRegion.find(image1.png) or myRegion.find(image2.png):
          print("not found")
except findFailed:

But it cotinues crashing....

I know that Sikuli is well documented but i couldnt understand how fix it, so ...

could someone please give me an example how to handle findFailed without stop my script?
I know that i can use all these but i dont know how... "setFindFailedResponse(SKIP), setThrowException(False), a function to handle it, etc."

Note: am using python, Sikuli IDE on Linux Mint 19.03

Thanks, regards!

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:

Hello Mauso,

Thanks for your answer but it didnt work,

findAny, findAll, findBest ... i tested all of them and they choose similar images but not the correct one.

I definetly need to use find()

masuo (masuo-ohara) said : #3

Try similar() and exact().

[sample code]
r = Region(0,0,500,500)
anylist = r.findAny(Pattern("1592122231908.png").exact(),Pattern("1592122242862.png").exact())
if len(anylist):
    print "found"
    for m in anylist:
        if m.getIndex() == 0:
    print "not found"

Thanks Masuo, it is working now!

I just did this...

rightRegion = Region(1186,447,173,63)

if rightRegion.findBest(Pattern("1592064085453.png").similar(0.98)) or rightRegion.findBest(Pattern("1592064049381.png").similar(0.98)):
    print "on screen"
    print "is not there"

Thanks again!

Will be great if someone gives an example to handle find().
Am going to keep this open for a little more just in case.

Can you help with this problem?

Provide an answer of your own, or ask Javier Gonzales Rodriguez for more information if necessary.

To post a message you must log in.