Search code examples
rubytestingautomationautomated-testswatir-webdriver

Watir - Find elements using partial text


Is there a way to find an element by the text it contains?

Given:

<div>foobar</div>

browser.div(text: contains('foo')).present?   
# => true

Solution

  • Yes! Just use a regular expression:

    browser.div(text: /foo/).present?