Use CSS attribute selectors with Capybara

Posted About 13 years ago. Visible to the public.

You can use CSS attribute selectors Show archive.org snapshot in your step definitions like this:

Then /^the page should have a meta description "([^"]+)"$/ do |description|
  page.should have_css("meta[name=\"description\"][content=\"#{description}\"]")
end

Note that you need to always quote attribute values or you will get a Nokogiri parsing error like this:

unexpected 'foo' after 'equal' (Nokogiri::CSS::SyntaxError)
Henning Koch
Last edit
Over 11 years ago
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-04-15 12:06)