This should be an easy one but it is giving me trouble. Given this structure:
<root>
<a>
<b/>
</a>
<a/>
</root>
I'm trying to formulate an xpath expression that gives only the non-empty "a" elements, i.e. the ones that have child elements. Therefore I want the first instance of "a" returned, but not the second.
So far I have "/root/a/self::*" but that is returning me both a's.
As defined in the W3 XPath 1.0 Spec, " child::node() selects all the children of the context node, whatever their node type." This means that any element, text-node, comment-node and processing-instruction node children are selected by this node-test.
The key part of this XPath is *[1] , which will select the node value of the first child of Department .
Start by writing out the selenium Xpath for the parent and then traverse to desired object using back slashes like so; Xpath Parent written as //div[@class='region region-navigation' using our previously shown syntax. Now you start to traverse through the HTML nodes down to desired object.
/root/a[count(*)>0]
will give any 'a' node with any kind of child node
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