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.
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.
