简体   繁体   中英

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"

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]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM