← 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:
ok here you are:

-- make this launchpad page visible in the browser and scroll it to top so the Sikuli logo is fully visible in the upper left corner
-- goal: be able to selectively click the main menu entries without using find

lines beginning with > have to be entered in your script in IDE

1-- new script in IDE

2-- make up the reference:
>menuOverview = sikuli-logo-captured # capture the logo

3-- in IDE click on the logo thumbnail to open the preview window
4-- in the target offset tab: position the crosshair on menu entry "Overview"
5-- click ok

now the IDE has changed your logo image into a Pattern with a target
offset. If we would use it as click(menuOverview), the menu entry
"Overview" would be clicked.

Now you could implement all the other menu entries the same way (by duplicating the above line, changing the variable Name and position the target offset accordingly). 
An approach like this makes your script already more robust, because if one of the clicks work, all the others work too, because they are based on finding the same image.

But still for each menu entry, a new find operation is necessary (in
average 0.5 seconds).

To speed things up, we now calculate the menu positions and use these
click points instead.

>clickOverview = find(menuOverview)

now clickOverview contains a Match, whose click point targets the menu
"Overview".

since all menu entries are on one line, they share the same y
coordinates. Only the x coordinates differ.

to test the matches we use hover() and the slow motion run in the IDE

>hover(clickOverview)

should position the mouse over menu "Overview"

now the next menu entry "code": we calculate somehow the x offset to the
right of "Overview".

somehow ;-) Since I am mainly on Mac, I use the builtin screenshot tool,
to evaluate pixel coordinates. Any tool, that shows screen coordinates
of the current mouse location can be used for this purpose. Or use a
meter and calculate the pixels in a calculator based on your screen
resolution pixel/inch.

>clickCode = clickOverview.getTarget().right(55)

This is the magic:
getTarget() extracts the clickposition as a Location object (x, y) 
and right(55) makes a new Location 55 pixels to the right of this.

>hover(clickCode)

should hover over menu "Code".

and the next menu entry:
>clickBugs = clickCode.right(45)

In the end, we have only one find operation for the Sikuli logo and all
clicks immediately happen without an additional find operation: very
robust - very fast.

Hope this helps.

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