Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 367
uncledru Avatar asked Aug 02 '26 16:08

uncledru


1 Answers

Yes! Just use a regular expression:

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

like image 183
titusfortner Avatar answered Aug 04 '26 06:08

titusfortner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!