3

Below is the html code for two radio buttons, they only differ by "value" attribute

<input id="AmountOption" name="AmountOption" type="radio" value="1">
<input id="AmountOption" name="AmountOption" type="radio" value="2">

What Im trying to do is to choose the radio button with "value =2 "

I tried using "choose("AmountOption")" which choses the first radio button, but i want to choose the second radio button

How can i achieve this with "choose("")" method provided by capybara.

Any other alternatives are also welcome.

Thanks in Advance

1
  • 3
    The id of an element should identify that element uniquely. This means your html is not valid right now. Can you change the id?
    – RST
    May 6, 2013 at 12:20

1 Answer 1

6

Look at implementation of choose:

def choose(locator, options={})
  find(:radio_button, locator, options).set(true)
end

So it's obvious that you should invoke method set on some element.

:radiobutton selector supports only id, name and label so you can't use it and should use some other selector type:

find('#AmountOption[value=2]').set(true) # selector type is :css by default
2
  • Found a better solution for selecting the second radio button. I used "browser.find_element("//input[@value='2']").click " . The radio button selected using this. Anyways Thanks for your answer Andrey :-)
    – Kalyan
    May 7, 2013 at 6:43
  • 2
    @Kalyan an equivalent of page.driver.browser.find_element("//input[@value='2']").click is find(:xpath, "//input[@value='2']").click May 7, 2013 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.