xpath find node that does not contain child
34,161
//a[not(img)]
Try and avoid the //
if you can, though. Also note this will only exclude a
s that directly contain img
s.
Related videos on Youtube
Author by
Ben K.
Updated on March 29, 2020Comments
-
Ben K. over 4 years
I'm trying to create some xpath that will find all
a
tags that do not containimg
tags, so that something such as<a href="http://aol.com">link</a>
matches, but
<a href="http://yahoo.com"><img src="http://yahoo.com/logo.png"></a>
does not.
Of course I could do this in a two-part search but I'm sure there must be some way to do this with xpath.
-
Admin over 13 yearsXPath expression for "any
a
element not having animg
descendant element"://a[not(.//img)]
-
Kinjal Dixit almost 11 yearsI needed first td which did not have a link
//table/tr/td[1][not(a) and not(b)]
. The html had used td for table headers, and the table headers were wrapped in<b>
, so I had to skip those as well.