【问题标题】:Rspec & Capybara select optionRspec & Capybara 选择选项
【发布时间】:2015-05-07 16:53:50
【问题描述】:

我在表单中有一个选择器,我正在尝试选择一个选项然后提交表单。我不知道该怎么做。

<%=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 %>

我正在尝试执行以下操作。

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

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

【问题讨论】:

    标签: ruby-on-rails rspec capybara


    【解决方案1】:

    您需要使用选择字段的名称(我猜应该是“currency[prediction_days]”)。检查选择元素并找到它的名称。那么,

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

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多