Use XPath to select an element that does not have an img tag as a child.

Is it possible to select an h1 tag that does not contain any img tags with a single-line XPath expression? If so, what is it?

+5
source share
5 answers

Use the operator notand axis descendentto catch h1 tags without even a remote child img.

//h1[not(descendant::img)]
+9
source

You can use the function not():

//h1[not(descendant::img)]
+5
source
//h1[count(img) = 0]

, XHTML, XPath.

+3

h1 img:

//h1[not(img)]

h1 img:

//h1[not(.//img)]

//h1[not(descendant::img)]

which may be easier to understand when reading code.

+1
source

Try the following XPath expression:

//h1[count(img) = 0]
0
source

All Articles