What does this runtime error? FindFailed --- image not found on screen

Asked by joao

http://img808.imageshack.us/i/runtimeerrorz.png/

I'm using a Win7 guest Virtualbox and I get this message when I try to run the executable. It may be because I put a doubleclick where perhaps there should be a click and the program may be looping itself into warning me there are other isntances running, as that's what I'm getting too. But I want to make sure I have to restart it from scratch, as you can see from my other question. What I really don't understand is why it can't find stuff like the png's, which are all sitting down in the py folder. What png files is this exe file calling? And of course I don't understand the other things mentioned and I would love it if you could clarify it to me, thanks.

Question information

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

this is simple FindFailed error (the image you are looking for in your script line 59 was not found).

To understand the situation: http://sikuli.org/docx/region.html#finding-inside-a-region-and-waiting-for-a-visual-event and http://sikuli.org/docx/region.html#exception-findfailed

Revision history for this message
joao (joaodedeus1) said :
#2

Hi, after reading a bit more about regions and finding regions, I was wondering if you could help me on trying to visualize what finding a region looks like in the sikuli programming interface. Would it be something like:

click(image1.png)
find.Region(region.png)click(thing inside region.png)
click(image2.png)

Image1 and image2.png are outside the region. I want to click something inside the region in the second line. How can I leave the region and enter it for the clicking? I've tried it this way and it isn't working. I'd greatly appreciate a little push thanks.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

especially in the beginning or when starting a new case, it helps to store found regions for later use, use the slow motion mode and Region.highlight() to see what happens.

--- storing things:

match1 = find("image1.png")
click(match1)

is the same as click("image1.png"), but now we have stored the region, that image1 occupies on screen and can use it later on.

another possibility:

click("image1.png")
match = getLastMatch()

we get the same region, since every find operation stores the last match.

--- using stored things to make new ones

Supposing we have found something and stored the match in match1. we know that something else can be found in an area right of this object. So we define this other area based on the thing we know: match1.

reg1 = match1.right().nearby(100)
reg1.highlight(3) # watch the new region for 3 seconds

---- looking inside of regions

It is always a good idea, to restrict find operations to a smaller region than the whole screen. This speeds up things and avoids finding things you did not mean.

the blathering way - but more obvious:

match1 = find("image1.png")
click(match1)
reg1 = match1.right().nearby(100)
reg1.highlight(3)
match2 = reg1.find("imagex.png") # searched only inside reg1
click(match2)

the compact form as it is defined in the API

click(match1)
getLastMatch().right().nearby(100).click("imagex.png") # currently buggy

but we have a bug in the moment with Region.click(), so you have to write it this way:

click(match1)
click(getLastMatch().right().nearby(100).find("imagex.png"))

Find your own way and have fun.

Revision history for this message
joao (joaodedeus1) said :
#4

So following the last example, shouldn't this work:

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

But it doesn't so I must be missing something. It fails at the click get last match line. I've tried creating a region instead of the region.png, and then it doesn't work at the match1 line.

I also want to be able to leave a region and forget it entirely, but many of these rules seem to determine the rest of the clicks to the match. I'm not sure I understood this rule:

click("image1.png")
match = getLastMatch()

When was the match declared and related to an area?

I would like to kind of hover over an area, or declare it as a match. And then click inside an image inside that area. Clicking the region would probably be an error for me.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

--1.
match1 = find(region.png)
click(getLastMatch.find(imageinsideregion.png))

getLastMatch is a function call and has to be: getLastMatch()

so:
match1 = find(region.png)
click(getLastMatch().find(imageinsideregion.png))

should work (I suppose, the apostrophes with the image file names are only missing here, not in your script)

-2.
All things are transient (get obsolete) at the end of processing any click, find, hover, or whatever. they are only preserved if you save them in variables for later use - so it is your decision.
an exception is getLastMatch(), which recalls the last match of a region, that is stored by any find operation.

in this sense:

click("image1.png") # does not remember anything
match = getLastMatch() # you use this, because you decide to remember the region, that image1.png occupies
# just leave it, if you do not need it

If you do not specify a region, the default region SCREEN is used, that usually is the primary screen or Screen(0).

so
find(some-image)

and

SCREEN.find(some-image)

and

Screen(0).find(some-image)

are aquivalent.

--- 3. you ask
When was the match declared and related to an area?

a match is "declared" by a find operation and saved as LastMatch (use getLastMatch() to get it) in the region that was searched. a match is not related to an area, it IS an area itself, like a Region, only with some more information (e.g. a dedicated click point).

use
print Region(SCREEN) # it is a Region
print find("region.png") # which is a match

and you can see it.

--4. you ask
I would like to kind of hover over an area, ....

ok, just do it:
match = find("region.png")
hover(match)
wait(3) # so you can see the mouse hovering
click(match.find("the-image-to-click.png")

Revision history for this message
RaiMan (raimund-hocke) said :
#6

sorry closing bracket missing in last line:

click(match.find("the-image-to-click.png"))

Revision history for this message
joao (joaodedeus1) said :
#7

Hi thanks for your help. I got the match statements to work like this:

match = find(region.png )
click(match.find(imageinsideregion.png))

However, I couldn't get your getlastmatch to work:

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

Tried it with and without apostrophes. I'd like to know for future reference what I'm doing wrong.

Also, could you be so kind as to visualize for me how to work with if statements. Sort of:

if(a certain image appears.png)
wait(10)
click(a.png)
if(it does not appear.png)
wait(10)
click (b.png)

Revision history for this message
RaiMan (raimund-hocke) said :
#8

--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.

Can you help with this problem?

Provide an answer of your own, or ask joao for more information if necessary.

To post a message you must log in.