What are the best Selenium locators to find particular text on a webpage? or How can I use Selenium l

14 Replies, 1349 Views

If you’re dealing with dynamic text or i18n, XPath/CSS might not cut it.

Try regex in XPath (if your lib supports it):
`//*[matches(text(), 'your_regex', 'i')]`

Or use JavaScript executor to fetch elements by text:
```js
return document.evaluate("//*[contains(text(), 'your_text')]", document, null, XPathResult.ANY_TYPE, null);
```

Clunky, but sometimes the only way.

Messages In This Thread



Users browsing this thread: 1 Guest(s)