Given the following XML:
abcText1cba
abcText2cba
//li[./span[contains(text(),'Text1')]] - have just one target result
//li[./span[contains(text(),'Text')]] - returns two results as target
This approach is using something that isn't well documented anywhere and just few understands how it's powerful
Element specified by Xpath has a child node defined by another xpath
Try this XPath
li/*[@innertext='text']
Your current xpath should be correct. Here is an alternative but ugly one.
XmlNodeList nodes = doc.SelectNodes("//span/parent::li/span[contains(text(), 'Text1')]/parent::li");
We find all the span-tags. Then we find all the li-tags that has a span-tag as child and contains the 'Text1'.
OR simply:
//span[contains(text(), 'Text1')]/parent::li
Just for readers. The xpath is correct. OP: Perhaps xpath parser didnt support the expression?
/root/li[span[contains(text(), "Text1")]]