I am writing a test suite for a Rails code base of mine and am trying to click on a search icon using Capybara and check if the search field appears. However, the test keeps failing as Capybara cannot find the CSS element "search_icon". I have tried using click_on()
and find(CSS).click
, but neither work. The former returns the error
1) Contents search clicking magnifying glass makes search box appear Failure/Error: click_on('search_icon') Capybara::ElementNotFound: Unable to find link or button "search_icon" # ./spec/features/contents/contents_search_spec.rb:13:in `block (2 levels) in '
and the latter returns
1) Contents search clicking magnifying glass makes search box appear Failure/Error: find('#search_icon').click Capybara::ElementNotFound: Unable to find css "#search_icon" # ./spec/features/contents/contents_search_spec.rb:13:in `block (2 levels) in '
This is the RSpec desription
scenario "clicking magnifying glass makes search box appear" do
visit contents_path
find("#search_icon").click
#Also tried this:
#click_on('search_icon')
expect(find("#search-form").visible?).to be true
end
that attempts to find this 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 an issue with my RSpec scenario code or how else could I find and click on this element?
page.find("#search_icon").click
- Pavana
element, with thehref='#'
. That way, you can click on the link itself, while the icon is seen as a label, in a way - onebree