I have this xpath expression that does not work
"//div[child[0]::h4[text()[contains(.,'Dir')]]]/a"
To parse this html:
<div class="txt">
<h4 class="c1">
Dir
</h4>
<a href="/name/myname/">Bob</a>
</div>
I am trying to get at the link node (a). There are other html tags in the document with the same div/h4 hierarchy, with the only difference being the innertext of the h4 tag. So how do I check that the div class (1) has a sub h4 node with inner text "dir" AND (2) get the first link node (a). Do not assume the link is the next sibling of h4.
child[0]::is incorrect. If you wanted the firsth4child ofdiv, you could use//div[child::h4[1][text()[...]]/a, or just//div[h4[1][text()[...]]/asincechild::is implicit for elements. If theh4must be the first element child, then//div[*[1]/self::h4[...]]/a.