Capybara Choose radio button not working

Viewed 5418

I've done this maybe 100 times but for the life of me I can't understand why it's telling me it can't find this object. Here is my html:

PS I've verified that I'm on the correct page and I can see the advisor when I do a save_and_open_screenshot

HTML

<div class="panel">
  <%= form.label :advisor, class: "panel__label" %>
  <%= form.radio_button :advisor_or_client, "advisor", class: "panel__input__radio advisor" %>
</div>

<div class="panel">
  <%= form.label :client, class: "panel__label" %>
  <%= form.radio_button :advisor_or_client, "advisor", class: "panel__input__radio client" %>
</div>

TEST

choose('advisor')

ERROR

Failure/Error: choose('advisor')

 Capybara::ElementNotFound:
   Unable to find radio button "advisor"

Screenshot

enter image description here

Based on the info provided how can I select the radio button for my feature spec?

1 Answers

choose locates the radio button by name, id or label text - http://www.rubydoc.info/gems/capybara/Capybara/Node/Actions#choose-instance_method . Rather than that you are specifying the value of the input (I'm assuming the second value should be "client" rather than the "advisor" you have). Since you don't have ids, and name would be ambiguous, you can use the option parameter (matches value) to narrow down to the correct radio. Therefore

choose('trade_request_submission[advisor_or_client]', option: 'advisor')

or potentially

choose(option: 'advisor')  # if you don't have any other radios with that value

Another option is to specify the label text but that would require adding the ids to the input elements that match the for attributes on the labels to link them correctly, in which case you could do

choose('Advisor')
Related