Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choose second radio button using capybara

From the following html how can i choose the second radio button .In the page load first radio button is selected when i use the following code

page.choose('#PPRINT')

<div id="printOpns" class="span6">
<div class="row"> <div class="span2" align="center">
<input id="Print" class="radio" type="radio" checked="" value="EPrint" name="printO"></div>
</div>
<div class="row"><div class="span2" align="center">
<input id="PPRINT" class="radio" type="radio" value="FPrint" name="printO">
</div>
</div>
</div>
like image 825
divz Avatar asked May 28 '13 07:05

divz


People also ask

Can you select more than one radio button?

Only one radio button in a given group can be selected at the same time.

Why can I select multiple radio buttons?

This means that you have two radio groups, each containing one radio button. You need to put them in the same group (by making them share a name) if you only want one of them to be selected.

How do I assign a radio button?

To label a radio button, add a <label> element after the <input> element and insert a for attribute with the same value as the id of the associated <input> element. Then, write your label text in the <label> tag. While using <label> isn't strictly necessary, it's considered a best practice for two reasons.


1 Answers

The Capybara API for the choose method says "Find a radio button and mark it as checked. The radio button can be found via name, id or label text." This means that the text that is supplied to the choose method must match the name, id or label of the radio button.

choose does not support css-selectors. Therefore, when you do:

page.choose('#PPRINT')

Capybara is looking for a name, id or label that equals "#PPRINT".

You want to do (ie no "#"):

page.choose('PPRINT')
like image 129
Justin Ko Avatar answered Oct 26 '22 23:10

Justin Ko