水豚:无法为collection_select和text_field_tag找到CSS

时间:2019-06-23 15:30:10

标签: ruby-on-rails-5 capybara

我有一个collection_selecttext_field_tag,像这样:

<%= form_tag method_path(@test.id), method: :get  do %>
  <%= collection_select(:test, :id, Test.all, :id, :id, prompt: true, include_blank: 'Select Test') %>
  <%= text_field_tag(:input_test_questions, 'Test ids') %>
  <%= submit_tag "Add" %>
<% end %>

这将生成以下html:

<select name="test[id]" id="test_id"><option value="">Select Test</option>
  <option value="1">1</option>
  <option value="2">2</option>
</select>
<input type="text" name="input_test_questions" id="input_test_questions" value="Test ids">
<input type="submit" name="commit" value="Add">

我正在尝试使用Capybara进行上述集成测试。为了选择和输入,我这样写:

select "2", from: "#test_id"
fill_in "input_test_questions", with: "1"

但是我遇到以下错误:

Capybara::ElementNotFound: Unable to find css "#test_id"
Capybara::ElementNotFound: Unable to find field "input_test_questions" that is not disabled

如何纠正错误,以便Capybara找到并选择并填写上述选项?

1 个答案:

答案 0 :(得分:1)

selectfrom选项用于通过其名称,id,test_id属性或标签文本来定位