Search code examples
rubywatir-webdriver

How to get meta tag content value in Watir?


I'am not able to get the content value of meta tag from site in Ruby using Watir-webdriver gem.

e.g.

<meta property="og:title" content="【楽天市場】ダヴ メンプラスケア クリーンコンフォート泡洗顔 つめかえ用(110mL)【unili3e102】【ダヴ(Dove)】[ダヴ 洗顔]:爽快ドラッグ">

Solution

  • The problem with browser.meta(:property, 'og:title').content is that "property" is not a valid attribute for meta tags. As a result, Watir does not allow it as a locator method.

    To locate elements via unsupported attributes, you will need to use a CSS-selector:

    browser.meta(css: 'meta[property="og:title"]').content
    

    Or use XPath:

    browser.meta(xpath: '//meta[@property="og:title"]').content