Distinguishing between Active and Grey text

Asked by MySikuliExp

What is the most efficient way to distinguish between active text and grey or inactive text/button or command? I did a simple experiment on Windows to try and empty the recycle bin. The two line program works fine. But when the recycle bin is empty:

1. The image of the full recycle bin and the empty recycle bin match and the program continues to next command.
2. The next command is to click on the 'Empty recylce bin' text in the drop down menu after right click on the recycle bin image. This command also returns a success. When the image is not exactly same, the text now is grey as the bin is empty.
3. This command where it is waiting for the dialog box which gives the option 'Yes' empty the bin, fails as the dialog box never appeared.

I would have ideally liked it to fail in the first line, or at least in the second. Is there a better way to make this fail if the text is not active?

Question information

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

This is one of the more tricky things in Sikuli.

The only chance, to solve this, is to use the similarity score (but might not always work).

And in some cases it is necessary to narrow the region to the area, where you expect the image to be, to avoid false positives.

In the case of active/inactive buttons/menu entries, take an image of the active version ("active-img.png") and try:

if exists("active-img.png").similar(0.99): # do not use 1.0 or exact() - buggy
    print "should be the active one"
    click(getLastMatch()) # and click it
    # other follow up actions
else:
    print "nothing to do"

If your challenge is more complex (both variants have to be used with a search), you can normally assume, that a correct match has a similarity score above 0.95 and a false positive a score below 0.95

You might run some tests like:
print exists("active-img.png")
print exists("inactive-img.png")

in the different situations to find out the threshold.

Can you help with this problem?

Provide an answer of your own, or ask MySikuliExp for more information if necessary.

To post a message you must log in.