← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #205413]: trying to trap errors in sikili script not quite working

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
If the standards are in effect, find() will abort the script if not
found.

exists() always returns with either None (which is false) or the match
object (which is true). So exists() usually is the first choice to check
wether something is there, before going on.

your case:

# find("1344004317402.png") # delete it - does not make sense, you use exists
if not exists("1344004317402.png"):
    print"[error]: Can't Start Application"
    exit(1)
else: # not needed here, since script will end if not found anyway
click("1344004329798.png") # next statement, if above image is found

so what is left:
if not exists("1344004317402.png"):
    print"[error]: Can't Start Application"
    exit(1)
click("1344004329798.png") 

Another trick, to make the script robust:

if not exists(some_image): print "problem"; exit(1)
click(getLastMatch()) # no additional search, if the image just found should be clicked

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