← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #161233]: How to resolve intermittent FindFailed exceptions

 

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

RaiMan proposed the following answer:
--- use wait/exists for individual waiting and click(getLastMatch()) to click the found match
this solution targets the "possible reason 1" in the above comment #1.
In general you split the click(image) in a wait(image, timeout) or exists(image, timeout) and a click(getLastMatch).
here is an example: faq 1501
Another advantage of this approach: You might implement recovery/corrective actions, in cases, where the workflow might fail if you use a plain click(image).

--- restrict the find operations to the region, where it should find the visual object.
Sikuli makes it very easy, to just start with some clicks and finds. These act on the whole screen. 
disadvantages:
- searches last rather long (might be more than 1 second)
- you run the risk, that something is found, that you did not mean (something similar somewhere else on the screen with an even or higher score)
So in general it makes sense, to restrict the find operations to the region on the screen, where your visual objects should be (we call it region of interest (ROI)).
The Sikuli features that support ROI are:

- class Region
e.g. r.click(image) looks for the image inside the region r 
every action with respect to that region, has to be qualified with that region:
if r.exists(image): click(r.getLastmatch())

- with region:
all actions in the with block are automatically qualified with region:
reg = someRegion
with reg:
    if exists(image): click(getLastmatch())

- setROI()
makes only sense with the SCREEN region (default region)
example:
find(image) # searches whole screen
setROI(Region(0,0,300,300))
find(image) # searches only in upper left (300x300) of screen
caution: other than with with: it is not obvious when reading a part of a script, that may be a setROI() is active at that point.

The so called spatial operators (http://sikuli.org/docx/region.html#extending-a-region) can be used, to easily make new regions based on existing ones:
example: define the different areas of an application window (pixels are measured somehow ;-):
winSomeApp = App("someApp").window()
th = 20
mh = 50
titleBarSomeApp = winSomeApp.above(1).below(th)
menuBarSomeApp = titleBarSomeApp.below(mh)
contentSomeApp = menuBarSomeApp.below(winSomeApp.h - th - mh)

Now you have three regions, that represent the main areas of your
application window - and this works independently from the window size.

more examples can be found in the respective parts of the docs.

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