Is there a way to test 'enabled'/'disabled' status of a button?

Asked by Landy

I need to verify a menu item is enabled or disabled. The text is same in both status. The only difference is the text is gray in 'disabled' status.

I take snapshots for both status, and write codes as

print find("disabled.png")
print find("enabled.png")

I expect the similar score have difference so I can use a score boundary to distinguish them. But, the result is: both have same score (0.98)... It looks like the gray or not doesn't effect the score. If so, is there a way to compare the difference? Thanks.

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

Sorry, that is a weakness of the current version (see bug 768940).

The only possible workaround is to try to evaluate other aspects of the disabled/enabled situation (e.g. what happens, if you hover the mouse pointer?)

Revision history for this message
ManxBug (llafrance) said :
#2

Just an suggestion. Why not click the button and test if the expected result happened. If not the button is probably grey.

Revision history for this message
Landy (landy-zhu) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Landy (landy-zhu) said :
#4

@ManxBug. Thanks for your suggestion.

 Yes, I'm using this workaround (click the button then see what happens), but I think it's not as direct as image comparing. For example, when I use a software, I can know the button is disabled or not by "seeing" instead of "clicking". :)

Revision history for this message
eliteSKL (camaro70s) said :
#5

can you check the score? an evaluate it that way? I assume this bug is going to give you varying scores... but it might work.

arg1="button-checked.png"
arg2="button-not-checked.png"

def is_it_clicked(arg1,arg2):
     reg=Region()
     score_one=reg.exists(arg1,0).getScore()
     score_two=reg.exists(arg2,0).getScore()
     if score_one<score_two:
          print "button is checked"
     elif score_one>score_two:
          print "button is not checked"
     else:
          print "ugh..... it's a bug and i can't figure it out.... wait till next release."

Revision history for this message
Landy (landy-zhu) said :
#6

@eliteSKL. It looks like a good way. I'll try it out. Thanks.