bsky
bsky

Reputation: 20242

Rspec & Capybara select option

I have a selector within a form and I am trying to select an option and then submit the form. I'm not sure how to do this.

<%=form_for @currency do |f| %>
    <%= f.label "Days" %>
    <div id="select_days" >
    <%= f.select(:prediction_days, options_for_select(1..30)) %>
    </div>
    <%= f.submit "Predict", class: "btn btn-primary" %>
<% end %>

I'm trying to do something like the following.

find(:xpath, '//div[@id=\'select_days\'').select_option('5')

or

select "5", :from => "select_days"

Upvotes: 0

Views: 1249

Answers (1)

roxxypoxxy
roxxypoxxy

Reputation: 3121

You need to use the name of the select field (which I guess should be "currency[prediction_days]"). Inspect the select element and find it's name. Then,

select "5", :from => "name-of-select-field"
eg: select "5", :from => "currency[prediction_days]"

Upvotes: 2

Related Questions