XPath //div[contains(text(), 'string')] fails to select divs containing 'string'
html, xpath
Solution
Replace `text()` with `string()`:
//div[contains(string(), "Elangovan")]
Or, you can check that `span`'s following text sibling contains the text:
//div[contains(span/following-sibling::text(), "Elangovan")]
Also see:
- Difference between text() and string()
Problem
This is the HTML code: ``` <div> <span></span> Elangovan </div> ``` I want to write an XPath for the `div` based on its contained text. I tried ``` //div[contains(text(),'Elangovan')] ``` but this is not working.