ruby on rails - Capybara RSpec Not Finding and Clicking CSS Element -


i writing test suite rails code base of mine , trying click on search icon using capybara , check if search field appears. however, test keeps failing capybara cannot find css element "search_icon". have tried using click_on() , find(css).click, neither work. former returns error

1) contents search clicking magnifying glass makes search box appear failure/error: click_on('search_icon') capybara::elementnotfound: unable find link or button "search_icon" # ./spec/features/contents/contents_search_spec.rb:13:in `block (2 levels) in '

and latter returns

1) contents search clicking magnifying glass makes search box appear failure/error: find('#search_icon').click capybara::elementnotfound: unable find css "#search_icon" # ./spec/features/contents/contents_search_spec.rb:13:in `block (2 levels) in '

this rspec desription

scenario "clicking magnifying glass makes search box appear"   visit contents_path    find("#search_icon").click    #also tried this:   #click_on('search_icon')    expect(find("#search-form").visible?).to true end 

that attempts find element

<div class="pull-right has-tooltip" data-title="search" id="search_icon" data-original-title="" title="">  <i class="glyphicons-icon search"></i>  </div> 

is there issue rspec scenario code or how else find , click on element?

#click_on alias #click_link_or_button click <a href=...> or <button> elements. usage of #find , #click correct way doing this, depending on css you're applying actual icon possible div has width and/or height of 0px - make unclickable. instead try clicking on actual icon using like

find('#search_icon .search').click 

also -- expectation @ end read better if use capybara rspec matchers

expect(page).to have_css('#search_form', visible: true) 

the visible: true needed if have changed capybaras default of finding visible elements


Comments