← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #151368]: What does this runtime error?

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
--1. apostrophes
the filenames of the images used have to be written in surrounding apostrophes

e.g.
match = find("region.png" )
click(match.find("imageinsideregion.png"))

Since you say it is running for you, I suppose that you have it
correctly written in your script (you do not see the " because the
filenames are substituted by the image thumbnails)

--2. getLastMatch()

usage exactly as you wrote:

match1 = find("region.png")
click(getLastMatch().find("imageinsideregion.png"))

though this usage does not really make sense, since you have the match
already in match1.

find("region.png")
click(getLastMatch().find("imageinsideregion.png"))

would make sense, since you did not save the match with
find("region.png")

--3. how to make decisions with if
Sikuli scripts are written in Python language. If you are new to Python it is a good idea to read across the first 2 chapters of http://jythonpodcast.hostjava.net/jythonbook/en/1.0/

Look at faq 1483: it talks about getLastMatch() and has examples of if-
else constructs.

and look through this faq 1437. it talks about repeating (which will
definitely be your next question ;-) and indentation/dedentation and has
again some examples for if's.

Before you trap in:
Never use find() in an if statement, always use exists() instead.

your above example:

if exists("a certain image appears.png", 10): # wait max 10 seconds
   wait(10) # I do not think this is needed
   click(a.png)
else:
   wait(10) # I do not think this is needed
   click (b.png)

When you expect, that there are latencies with images to get visible,
just use wait() or exists(), where you can specify the time to wait.
advantage: the script continues in the moment the find is successful,
wait(10) always waits 10 seconds.

so again the above example:

if exists("a certain image appears.png", 10): # wait max 10 seconds
   click(wait("a.png", 10))
else:
   click (wait("b.png", 10))

if a.png or b.png are not found within 10 seconds, the script stops with
a FinsFailed exception.

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