I am trying to figure out the XPath which will retrieve the 'text Data 3' from the following HTML snippet
<span class="inner-span">
Text-data 1
<br>
<span>Text Data 2</span> text Data 3
</span>
So far i have tried the following Xpath which leads me to the span with class 'inner-span'
/html/body/div/div[4]/div[2]/div[2]/div/div[2]/div/span[@class="inner-span"]
But dont know what to add more to Xpath which will only give me text 'text Data 3' from above Html snippet. Thanks
For your particular case this XPath query would work:
normalize-space(//span[@class="inner-span"]/text()[last()])
Tried it in this online tester and here's the result:
You could select /html/body/div/div[4]/div[2]/div[2]/div/div[2]/div/span[@class="inner-span"]/text()[last()]
to get the text node (though with leading and trailing white space) or you can use an XPath returning a string with normalize-space(/html/body/div/div[4]/div[2]/div[2]/div/div[2]/div/span[@class="inner-span"]/text()[last()])
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With