Xpath syntax to grab text data after strong tag containing header text
<li><strong>Movie Title:</strong> Training Day</li>
How to grab the text content in this li tag; "Learning Day"?
So I need to say, "If the strong tag has" Movie Title "return" Learning Day ".
I've tried things using "next brother" but can't seem to figure it out.
Another try -
//li/text()[preceding::strong[contains(text(),'Movie Title')]]
But this returns ALL text, not just what is inside the li class.
+3
source to share
2 answers
How to grab the text content in this li tag; "Learning Day"
So I need to say, "If the strong tag has a Movie Title, return" Learning Day ".
The following XPath expression selects all li-element text nodes after the strong element whose value contains the string Movie Title.
//li[contains(strong,'Movie Title')]/strong/following-sibling::text()
In your XML example, this is the "Learning Day" result.
But if additional text-nodes follow, you will need to constrain the expression to the first text-node like this
//li[contains(strong,'Movie Title')]/strong/following-sibling::text()[1]
0
source to share