I want to use xPath to find links on a page, but only the ones with actual content:
So I do want to find: <a href='test.html'><img src='test.jpg'></a>
And <a href='test.html'>link</a>
But not: <a href='test.html'></a>
So far I tried: //a[text()] which finds the 2nd link in the example and skips the last one, but it also doesn't find the first one... I want to find that first one as well. How would I go about this?
Something like this should work
//a[text() or *]
That should get you all <a> elements with at least one child node (including text).
Demo ~ http://www.xpathtester.com/xpath/0971a775fc7ac19b5b631a760c4aba9d
This is a great cheat-sheet for XPath expressions ~ https://devhints.io/xpath
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