How to click on a particular check box?
(For Sikuli Version 0.10)
The goal is to asure, that the a checkbox is checked (in this case: the one that the red "click" in the picture below points at). We evaluate the current setting and click it on, if it is off.
The workflow is designed for a Mac, but the approach can easily be reproduced with an applicable dialog box on a windows or linux system.
The example supposes, that the relevant system preferences pane (Dock in this case) is already open and the frontmost window.
To minimize the risk of not found errors and to increase the performance, we set a "Region of Interest (ROI)", which is the rectangle occupied by the content part of the dock pane. We define the ROI based on the match of the title area as the region below that title (currently it is fixed at about 300 pixels). If you don't know how large is the window, that's also fine. Feel free to just use ".below()" without a specified range. In this case, Sikuli extends the region below the title bar to the bottom edge of the screen.
find() setROI(getLastMatch().below())
If you are sure about the size of the window, using setROI(getLastMatch().below(300)) can speed up the search.
We will use find(
) to locate the checkbox.
By design, you can click on this text to toggle the setting, so we don't need an extra click point.
Adjusting the click point with the preview "Pattern Settings"
In cases where you really have to click on the checkbox, you can use the feature "Pattern settings" (just click on the thumbnail), where you can define a click point different from the center using the tab "Target Offset".
In our case, the resulting target offset would be (-137, 0). After you click on "OK", the resulting pattern in the click command will have a small red cross to indicate the target location.
So if we use this feature in our case, no matter where the actual location of our checkbox is on the screen, the click() would always be on the checkbox left of the text.
Now we evaluate the current setting. The appropriate function is exists(), which checks whether an image can be found and returns either True or False, without raising a FindFailed exception. We look into a small region left of our text for the image of a checked check box.
Only if the check mark is missing, we click on the text.
The successful find saves its best match. So in this case we can use getLastMatch(), since the unsuccessful find with exists() leaves this untouched.
if not find().left(50).exists(
): click(getLastMatch())
Sikuli script provides many more features to handle even complex situations in an elegant way. If you are interested, look at other Examples, Tutorials, HowTo's and especially at The Complete Guide to Sikuli Script.
Attachments
-
dock.png
(51.2 KB) - added by RaiMan
2 years ago.
-
1272904139788.png
(1.9 KB) - added by RaiMan
2 years ago.
-
1272904216975.png
(353 bytes) - added by RaiMan
2 years ago.
-
1272904295395.png
(4.5 KB) - added by RaiMan
2 years ago.
-
1272904435843.png
(427 bytes) - added by RaiMan
2 years ago.
-
click-check.png
(51.0 KB) - added by vgod
2 years ago.
-
click-check-with-off.png
(10.2 KB) - added by vgod
2 years ago.

)


):