exists and click

Asked by Peter Kim

Hi.

Following code fails sometime:

    if v.exists("ga-1.png"):
        v.click("ga-1.png")

I checked the screen capture and found that the image was similar to ga-1.png but had a different background color.

So it seems that exists() thought the image existed but click() did not think so.

Question information

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

--- recommendation:

 if v.exists("ga-1.png"):
        click(v.getLastMatch())

so you do not have an additional find operation with the click, since the exists already found the image and you can now click the match.

--- You say: So it seems that exists() thought the image existed but click() did not think so.
Both functions (exists() and click() ) internally use the same find operation. So if the exists() does not find the picture, the click will not happen at all. If exists finds the picture, the click finds the same picture.
So I am not really sure, what you mean.

background color: you should try, to capture as little as possible of the background. The less you have in your capture, the more reliable will your search work in case of slightly changing background.

Revision history for this message
Peter Kim (pd-kim) said :
#2

Thanks RaiMan, that solved my question.