Ruby on rails 水豚找不到字段“;搜索“;
我尝试在表单的各个部分设置id,并将表单包装在一个div中,id设置为Ruby on rails 水豚找不到字段“;搜索“;,ruby-on-rails,capybara,Ruby On Rails,Capybara,我尝试在表单的各个部分设置id,并将表单包装在一个div中,id设置为search。结果总是一样的 规格/特征/02_post_规格rb spec/spec_helper.rb 这将重定向到post\u路径(post) views/posts/index.html.erb 假设您在页面上呈现所显示的部分,并且该部分的输出在页面上实际可见(不通过CSS隐藏),那么您使用的命令fill_in“search”(搜索)和:post3.title应该可以工作。您的场景不会显示访问实际页面的情况,也不会显示
search
。结果总是一样的
规格/特征/02_post_规格rb
spec/spec_helper.rb
这将重定向到post\u路径(post)
views/posts/index.html.erb
假设您在页面上呈现所显示的部分,并且该部分的输出在页面上实际可见(不通过CSS隐藏),那么您使用的命令fill_in“search”(搜索)和:post3.title
应该可以工作。您的场景不会显示访问实际页面的情况,也不会显示fill\u post\u form
在做什么,因此很难准确地知道到底出了什么问题。第一步是做如下事情
fill_post_form(post3) # already in your tests
sleep 2 # wait a few seconds to make sure above method has completed whatever actions it does
puts page.html # output the current page and take a look to see if your 'search' element is actually on the page
查看页面上表单的原始html。。。他很可能被称为某个稍有不同的领域。如果您试图基于id进行搜索,那么您可能还需要
fill_in'#search'
或类似内容。@TarynEastfill_in
根据要填充的输入元素的名称、id或相关标签文本进行搜索-它不接受CSS选择器,因此将fill_in'search',…
不搜索您是对的。这很简单,就像上错了一页。我盯着屏幕看太久了。谢谢。@n.milsht不客气,如果答案对你有帮助,别忘了接受,这样问题就会被标记为已回答
def fill_post_form(post)
visit new_post_path
fill_in 'Title', with: post.title
fill_in 'Body', with: post.body
click_button 'Create Post'
end
<%= form_tag(posts_path, method: :get, class: "block") do %>
<div class="form-group">
<div class="input-group">
<%= text_field_tag :search, params[:search], class: "form-control", id: "search" %>
<span class="input-group-btn">
<%= submit_tag "Search", name: nil, class: "btn btn-default" %>
</span>
</div>
</div>
<% end %>
Failure/Error: fill_in "search", with: post3.title
Capybara::ElementNotFound:
Unable to find field "search"
fill_post_form(post3) # already in your tests
sleep 2 # wait a few seconds to make sure above method has completed whatever actions it does
puts page.html # output the current page and take a look to see if your 'search' element is actually on the page