Serge Vinogradoff
Serge Vinogradoff

Reputation: 2272

XPath matcher does not work for meta tags

Have this html:

<!DOCTYPE html>
<html>
  <head>
    <meta content="my id" property="fb:app_id" />
    <meta content="app name" property="og:site_name" />
    <meta content="social post" property="og:type" />
    <meta content="bsa" property="og:title" />
    <meta content="bsa" property="og:description" />
    <meta content="http://will-ferrell.lvh.me:3000/" property="og:url" />
  </head>
</html>

Trying to do this:

expect(page).to have_selector :xpath, '//head/meta[@property="fb:app_id"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:site_name"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:type"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:title"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:description"]'
expect(page).to have_selector :xpath, '//head/meta[@property="og:url"]'

And it does not work. Says it can't find the selector. Any idea why?

Upvotes: 0

Views: 247

Answers (1)

Vakiliy
Vakiliy

Reputation: 871

For invisible elements need use option - visible: false

Example:

expect(page).to have_selector :xpath, '//head/meta[@property="og:url"]', visible: false 

Upvotes: 1

Related Questions