水豚:找不到 collection_select 和 text_field_tag 的 css

Capybara: Unable to find css for collection_select and text_field_tag

我有一个 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 和输入,我这样写:

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 找到并 select 并填充上述选项?

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