2015-05-07 181 views
0

我有一個表格內的選擇器,我想選擇一個選項,然後提交表單。我不知道如何做到這一點。Rspec&水豚選擇選項

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

回答

2

您需要使用選擇字段的名稱(我想應該是 「貨幣[prediction_days]」)。檢查select元素並找到它的名稱。然後,

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