
choose does not select radio button
Reported by jazen | August 5th, 2009 @ 07:18 AM
I have several radio buttons like this:
<input id="user_class" name="user[class"] value="PrivateUser" />
<input id="user_class" name="user[class"] value="CompanyUser" />
...
Selecting the second one using
choose "CompanyUser"
does nothing. After digging into the source the problem seems to
be
the Locater which doesn't check the radio-button's value but
it's
name instead.
I'm using latest cucumber/webrat gems.
I temporarily fixed this issue by overwriting the webrat step with:
When /^I choose "([^\"]*)"$/ do |field|
dom = webrat.current_dom
radio_button = Webrat::XML.xpath_search(dom, ".//input[@type='radio']").detect do |element|
Webrat::XML.attribute(element, "value") == field
end
Webrat::Field.load(webrat, radio_button).choose
end
This works as expected. :)
Comments and changes to this ticket
-
Larry Siden November 15th, 2009 @ 12:04 PM
I had the same problem. I have two different sets of radio buttons whose values are "yes" and "no". I had to resort to Jazen's method, which works, but is quite verbose!
-
Bryan Helmkamp November 15th, 2009 @ 04:17 PM
- State changed from new to resolved
Generally I prefer to locate radio buttons by a label instead of the value. This also allows the application code to change it's representation while keeping the test code passing, so long as the UI stays constant.
Would this work for you?
It seems to make sense that choose would locate by value as well, but right now I'm considering the locators to be "frozen" until they can be reviewed and updated together once before Webrat 1.0. When this happens, I think that's a good change to consider.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Ruby Acceptance Testing for Web applications.