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

14 Replies, 1118 Views

For me, relative XPaths + text() work best for selenium locators to find particular text.

Example:
`//div[@id='main']//p[contains(text(), 'lorem')]`

But if the text’s split across tags (like `<span>hello</span><span>world</span>`), you’ll need `string()`:
`//div[contains(string(), 'hello world')]`

Also, Playwright has better text-matching built-in if you’re open to switching tools.

Messages In This Thread



Users browsing this thread: 1 Guest(s)