capybara: Ambiguous match, found 2 elements matching xpath "/html"

I’m using capybara (2.0.1) and I’m getting this issue whenever I write an expectation such as:

page.has_content?

However, everything works if I rewrite this to:

find('body').has_content?

I’m not sure if this is the intended functionality or if I’ve misunderstood the new changes.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Reactions: 2
  • Comments: 22 (1 by maintainers)

Most upvoted comments

Done some more debugging on the issue. Did a sanity check and there aren’t multiple HTML tags on the page, but it seems like having a doctype of <!DOCTYPE html> is causing the issue. After removing the doctype everything passes.

@tonydaly nice catch. I added some JavaScript outside of the trailing HTML tag (in HAML), and it caused the same failure. Thanks for the conversation/fix 👍

Erugh ignore this. There was a tag outside of the closing </html>.

For me it’s this one causing the trouble:

<!DOCTYPE html>
<!--[if lt IE 7]><html class="lt-ie7"> <![endif]-->

<html>
...
</html>

As you can see even this parser recognizes that the multiple <html> tags are just comments and Capybara maybe shouldn’t raise an Exception 😃 I’m using 2.1.0

Sounds like you have multiple HTML tags on your page. As far as I know that’s not allowed by the HTML spec. See: http://dev.w3.org/html5/spec/single-page.html#the-html-element