Sikuli radio button with associated text

Asked by Helene Pedata

Hello!
   As a new Sikuli user I am having difficulty managing this region:

 Are you female: O Yes O No

where O is a radio button.

I would like to be able to
     determine if the Yes button is clicked
     given Yes is selected -> uncheck Yes button
     check No button

Is there a way to associated Yes/no with it's button?

Thanks
HP

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
Eugene S (shragovich) said :
#1

Hi,

Given you don't have any more similar radiobuttons in the SAME HORIZONTAL LINE, you can try something like that:

1. Create a pattern (image) of the "Yes" text
2. Create a pattern (image) of checked and uncecked radio button (any of them, since both are similar)
3. Apply the following code:

regionYes = yestext.left()
if region.exists("checkedButton.png"):
    regionNo = yestext.right()
    # there is no actual need to UNCHECK "yes" since radiobuttons of this kind shoudl be mutually exclusive
    regionNo.find("unCheckedButton.png").click()

Cheers,
Eugene

Revision history for this message
Eugene S (shragovich) said :
#2

Couple of mistakes I've made:

Instead of line:
regionYes = yestext.left()

Should be:
regionYes = find("yestext.png").left()

Instead:
if region.exists("checkedButton.png"):

It should be:
if regionYes.exists("checkedButton.png"):

Hope there are no more errrors like these. Anyway, if there are, let me know.

Revision history for this message
Helene Pedata (hpedata) said :
#3

Thanks Eugene! I'm trying it now. Will let you know :)

Revision history for this message
Helene Pedata (hpedata) said :
#4

Hi Eugene,
   The code does not seem to recognize the radio box to the left of the Yes text.

The condition
  if regionYes.exists("Checked_Button.png"): Fails
  else:
     regionYes.exists("UnChecked_Button.png"): Fails as well.

Thanks for you help!
HP

Revision history for this message
Eugene S (shragovich) said :
#5

Hi,

What can be a problem is that the radiobutton region is "shorter than your Yes region (if that makes sense? :) )
So make sure that when you create a pattern for "Yes" text, it will COMPLETELY COVER the radiobutton pattern to the left of it. Ideally, the radiobutton should be minimalistic(include only the radiobutton itself with no spare pixels above or below it) while the "yes" pattern should be a bit higher (with a couple extra pixels above and below).

BTW, you can use ".highlight(1)" method to see the exact area you are working on at the moment.
So, for example, when you find the "yes" text on the screen, you can first try something like that:

region = find("yesText.png").highlight(1) # 1 means - highlight it for 1 sec

Then when you expand the region, highlight it as well. This way you'll be able to see whether it completely includes the radiobutton. So:

region2 = region.left().highlight(1) # Here make sure that the radiobutton pattern is completely enclosed within this area.
region2.find("radiobutton.png").highlight(1)

This should give you a better ideas as where the problem is.

Revision history for this message
Helene Pedata (hpedata) said :
#6

Hello Again,
   Yes, make sense! Can you tell me if the linux version of Sikuli behaves differently than the mac version?

find("Yes.png").left() does not seem to work on the linux version.

The error is 'int' object has no attribute 'left'

I am assuming it is executing the find() and returning a match object. Then tries to perform the left() but cannot because left is not a function for a match object.

If i leave out the left, it does find the "Yes".

However if I perform the same command on the mac, it works as expected.

Thanks
HP

Revision history for this message
Helene Pedata (hpedata) said :
#7

Hi Eugene,
I just realized since it says int object, it is not finding the match. Right?
HP

Revision history for this message
Eugene S (shragovich) said :
#8

Hi Helene,

I don't know whether there are differences between the Linux and Windows or Mac versions however, if you see that the same code works on Mac, then it makes sense that there are. RaiMan probably will know better.

generally, if the match is not found, you will get a FindFailed exception so the error you're getting probably means that there is no such method.

Eugene

Revision history for this message
Helene Pedata (hpedata) said :
#9

Hi Eugene,
  Seems like I had focus issues yesterday resulting
In failed finds. At the time, I did not have exception handling so it was not obvious the find was failing.
 So I really did not see differences between the Mac and
Linux versions. I have made great progress and want to thank you for all your help!
Helene

Revision history for this message
Eugene S (shragovich) said :
#10

Happy to help :)

Revision history for this message
Krishna Teja (ktsunkara) said :
#11

Hi can any body help with the java code to select a radio button from multiple radio buttons

Can you help with this problem?

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

To post a message you must log in.