if exists and assert exists are not behaving same

Asked by Alex Yi

Hi,

To give a short background on what I'm trying to: I have list of datasets that I need to pick from a selector window.
Basically, I need to make sure that there is a dataset called "39W Anchor#Base Scenario 20110926". If this dataset happens to be at the top of the list then by default it is already selected meaning the image will be in black. Anywhere else, it will appear in white image.

So I have the following code:
if exists(Pattern("39W Anchor Loadset Unselected Version.png").similar(0.99)) or exists(Pattern("39W Anchor Loadset Selected Version.png").similar(0.99)):
            getLastMatch().highlight(2)
            #print getLastMatch()
            hover(getLastMatch())

This works. Selects the image that I want. Now at the end I do an assert exists for either one of them and following is the code:
assert (exists(Pattern("39W Anchor Loadset Unselected Version.png").similar(0.99)) or exists(Pattern("39W Anchor Loadset Selected Version.png").similar(0.99))

This fails for some reason. I have to lower the similarity level down to 95 percent to make this work but then if I do that, then when I have a dataset called "39W Anchor#Base Scenario 20110919", it will pass and then select this wrong dataset.

Am I using the assert statement wrong?

Thank you,

sincerely,

Alex Yi

Question information

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

Might be, that the hovering mouse forces the entry to look different.

So try to move the mouse somewhere else before.

Or if you only want to use the exists() stae from before with the assert (no extra search:

something like:

found = exists(Pattern("39W Anchor Loadset Unselected Version.png").similar(0.99)) or exists(Pattern("39W Anchor Loadset Selected Version.png").similar(0.99))
if found:
            getLastMatch().highlight(2)
            #print getLastMatch()
            hover(getLastMatch())

....

assert(found)

BTW: It seems you are searching on the whole screen, which is slow and error prone.
and if "Unselected" is not found, it waits the full 3 seconds before looking for "Selected"
So in worst case the check "exists() or exists()" lasts about 4 seconds.

- restrict the searches to a region and use reg.exists() and reg.getLastMatch()
- use exists(image, 0) to search only once (no need to wait)

both together might reduce the processing time to 1 - 0.5 seconds and below depending on the size of the search region.

Revision history for this message
Alex Yi (ayi) said :
#2

Hi RaiMan,

Thanks for the solution. That seems to work very well.
I was actually thinking about Region for some of the test.
Thank you for the advice.

sincerely,

Alex Yi