How to continue the process of specific variable when image is not found.

Asked by Lara

Hi Raiman,

Good day!
I need your help. I just want to ask on how I can continue the process of variable M if it's not found. The expected output should be like this, "If variable M cannot be find, it will record as FAILED and if variable M is found, it will record the getScore and PASSED".

Here is the code that I used:

Settings.OcrTextSearch = True
Settings.UserLogs = True
Settings.UserLogPrefix = "xxx.log"
Settings.UserlogTime = True
Debug.setUserLogFile("C:\Program Files\SikuliX\xxx.log")
m = find("1488336741526.png")
d = m.getScore()
Debug.user("Image Percentage")
Debug.user(str(d))
if d>0.99:
    Debug.user("Slicing Passed")
else:
    Debug.user("Slicing Failed")

I'm looking forward for your help, Thanks in advance Sir :)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

find() throws FindFailed exception, which needs a different approach with try/catch to sort out success/fail.

In your case it is easier to use exists() instead:

m = exists("1488336741526.png")
d = 0;
if m:
    d = m.getScore()
    Debug.user("Image Percentage")
    Debug.user(str(d))
if d>0.99:
    Debug.user("Slicing Passed")
else:
    Debug.user("Slicing Failed")

Revision history for this message
Lara (jhela) said :
#2

Thanks RaiMan, that solved my question.