How to debug: image does not exist, but exists() is returning true

Asked by Alex Yi

Hi,

I'm not sure why exists function is returning true here.

Here is my exists statement:
        if (exists("MIPO39WAncho-1.png")):
                popup("39W Anchor 20110926 scenario exists")

On my screen, this image does not exist or I should say not visible at the initial load. This image gets visible if you scroll down in the container. What I am trying to do is to look for the image on the initial container and if it's there then click on it otherwise scroll down and then look for the image once again and if there then click it.
If this image is not found then fail the test.

However, this image is getting found during the first if statement and I do not understand why.

Any idea?

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
Alex Yi (ayi) said :
#1

I wish I can show you the screen where I am looking for this image.
How do I attach an image file?

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

To track down such a problem, you have to find out, what Sikuli finds.

In your case do this:

        if exists("MIPO39WAncho-1.png"):
                # see comment
                print getLastMatch() # 1. match printout
                getLastMatch().highlight(3) # 2. red frame 3 secs and match printout
                hover(getLastMatch()) # run in slow motion and get blinking red circles at match
                popup("39W Anchor 20110926 scenario exists")

-- comment
These are the 3 most useful debugging options:
A find operation stores its last match in its region (your case the screen), which can be retrieved using getLastMatch()

-- 1. print the match and you get something like this:
Match[56,120 75x74 score=1,00 target=center]
It tells you where it was found and the similarity score

-- 2. shows a read rectangle for n seconds
and prints additional information, something like this
[log] highlight Match[56,120 75x74 score=1,00 target=center] for 2.0 secs

-- 3. move the cursor to the match using hover() ...
and run the script in slow motion, which shows blinking red circles for a moment at the target

Usually you will find, that something similar was found with a score below 0.9.
So raise the min similarity to 0.95 (max 0.99), to get only valid matches.

your case:
        if exists(Pattern("MIPO39WAncho-1.png").similar(0.95)):
                popup("39W Anchor 20110926 scenario exists")

the similarity can be set in the IDE using the preview pane (click on image thumbnail).
In the preview pane you can also check what is found on the screen with your image, but this is less accurate and reliable and not usable in some situations.

--- BTW: the conditional statement in an if/elif/while need not be in brackets.

--- One more thing: screen shots can be posted here
- by putting them somewhere in the net (Dropbox, ...) and post the link
- post a bug, which allows attachments
- send me a mail with attachment (-> https://launchpad.net/~raimund-hocke) (at best all together zipped with your .sikuli)

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

You're exactly right.
It was finding a similar image with a score of 0.71.

And thank you for the additional information as well.