Capybara can match elements outside of <body>

Capybara will match elements outside of a page's <body> tag.

For example, the step definitions below match <link> nodes in a page's <head>:

Then /^my browser should auto-discover the "([^"]*)" feed$/ do |slug|
  page.should have_css(
    'head link' +
    '[rel="alternate"]' +
    "[href='http://www.example.com/#{slug}/feed.rss']" +
    '[title="RSS feed (all cards)"]' +
    '[type="application/rss+xml"]',
    visible: false
  )
end

Then /^my browser should not auto-discover any RSS feeds$/ do
  page.should_not have_css('head link[rel="alternate"][type="application/rss+xml"]')
end
Henning Koch Over 12 years ago