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

14 Replies, 1075 Views

CSS `:contains` is a lifesaver *if* you’re using jQuery or a browser that supports it. But since most don’t…

Try XPath axes! Like `following-sibling::` or `ancestor::` to narrow down where the text lives.

Example:
`//div[contains(text(), 'hello')]/following-sibling:Confusedpan`

Also, Browser DevTools (F12) + `Ctrl+F` to test locators before throwing them into Selenium.

Messages In This Thread



Users browsing this thread: 1 Guest(s)