Reputation: 11711
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?
Upvotes: 3
Views: 477
Reputation: 164744
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
Upvotes: 2
Reputation: 29022
Simply try this
//a[text() or img]
to find all links with text or images(img
tags).
Upvotes: 1