Ensure an element is not present with Capybara

You can do this by making use of capybaras has_no_selector? method combined with rspecs magic matchers. You can then use it in this way:

 page.should have_no_selector(:xpath, "//input[@type="#{type}" and @name="#{name}"]")

You can see more details of the assertions you can perform on the capybara documentation page here under the section entitled Querying

Leave a Comment