How to get checkbox value from an application using Sikuli scripting

Asked by ambiga

Am trying to get the checkbox value (like whether it is ticked or unticked), of some windows properties.

How can we do that using Sikuli scripting?

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
Roman Podolyan (podolyan-roman) said :
#1

It's not that easy (no direct checkbox API), but possible, I think.

You should construct regions restricted to particular checkbox position, and then check if checkmark exists therer:

checkboxregion1 = ...
if checkboxregion1.Exists("Checkmarkimage.png"):
        checkbox1checked = True
    else:
        checkbox1checked = False

...

If you want more detailed code, please provide to me screenshot image of the checkboxes you talk about.

Revision history for this message
ambiga (ambigaj) said :
#2

Hi Roman,

Scenario 1:
==========
Am trying a simple pgm to check if a checkbox is ticked or unticked. Am using 2 images(one with the checkbox ticked and other with checkbox unticked). But it is treating both as same images, i.e., not differentiating the ticked symbol present.
Code:
--------
if exists("checkboxtickedimg.png"):
    popup("yes")
elif exists("checkboxuntickedimg.png"):
   popup("no")

Whether the checkbox is ticked or unticked, it is executing only the first loop.

==============================================================================

Scenario 2:
==========

Also i tried with the region concept, I created a small region in 'Taskbar and Start menu peoperties". And trying to analyse whether the tick mark exists in the 1st checkbox, using the below code:

regi = "TaskbarStart.png"
if (regi.exists("1355735603254.png")):
    popup("ticked")
else:
    popup("unticked")

Facing the issue:
==========
[error] Stopped
[error] An error occurs at line 2
[error] Error message: Traceback (most recent call last):
 File "C:\Users\ambigaj\AppData\Local\Temp\sikuli-tmp2205391485963534774.py", line 2, in
 if (regi.exists("1355735603254.png")):
AttributeError: 'str' object has no attribute 'exists'

Please help me out in this.

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#3

You doing it wrong.

regi = "TaskbarStart.png"

Here you just assign to regi a string value. Of course, Python thinks it's a string, so gives you error "'str' object has no attribute 'exists'"

Read more about Region - http://doc.sikuli.org/region.html#creating-a-region-setting-and-getting-attributes , and construct regi like a Region.

Something like that:

back_region = Region(0,0,70,50)
hover("xyz.png")
mouseloc = Env.getMouseLocation()
back_region.moveTo(mouseloc)

You should define region with Region(x, y, w, h), and then you may move it around to correct it's position.

Can you help with this problem?

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

To post a message you must log in.