Search code examples
javasikuli

How to select a radio button based on the text adjacent to it using Sikuli + Java?


How to select a radio button based on the text adjacent to it using Sikuli + Java ?

There are 3 radio buttons(with some text adjacent to them) present on the screen. Sikuli is always clicking on the second one. How can I click the other radio buttons?

The screen is as shown below. Treat that 'O' as a radio button and provide any solution for it. (I cant upload the screenshot hence I shown it as below)

  • O abcd
  • O efgh
  • O asdf

Now how can I click on the 1st or the 3rd 'O'(Radio button)


Solution

  • to give u an exact solution, it would be helpful to know if you are using sikuli-java-api or sikuliX-api. In any case the logic behind both would be same, that is-

    • first search for the image/screenshot of the text u need the radio button to be selected for and map it to Screen/Region, call this say TextRegion (depending on ur api again)
    • select the region to the left of ur TextRegion and map it to another Screen/Region, call this say LeftRegion
    • Now within LeftRegion, search for a subRegion to match to ur image of radio button. u can now select that subRegion and name it SelectedRegion
    • click on SelectedRegion

    You can create a generic method for this process, passing the image of the text for which u need the radio button to be selected and the image of the radio button as parameters. Also, you can use highlight to identify the subRegions that you have created. It proves useful in understanding where you might've gone wrong.