id를으로 설정하여 div의 양식을 줄뿐만 아니라 양식의 여러 부분에서 id를 설정해 보았습니다. 결과는 항상 동일합니다.Capybara 필드를 찾을 수 없습니다. "search"
사양/기능/02_post_spec.rb
scenario 'search for post title' do
fill_post_form(post3)
fill_in "search", with: post3.title
click_button("Search")
expect(page).to_not have_content(post1.title)
expect(page).to_not have_content(post2.title)
expect(page).to have_content(post3.title)
end
사양/spec_helper.rb
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
이 것 redirect_to post_path(post)
보기/글/index.html.erb
<%= 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"
페이지의 양식의 원시 HTML을 살펴 보겠습니다. 해당 필드가 다소 다른 것으로 불려질 가능성이 큽니다. id를 기반으로하는 경우, 'fill_in'# search'' 또는 유사한 것을 원할 수도 있습니다. –
@TarynEast'fill_in'은 칠할 입력 요소의 이름, id 또는 관련 레이블 텍스트로 검색합니다. - CSS 선택자를 허용하지 않으므로 fill_in 'search', ...'not #search –