Reputation: 3227
Let's have this xpath:
<div>
<!-- ... -->
<div> <!--I want this element-->
<!-- ... -->
<sometag>
<a></a>
</sometag>
<!-- ... -->
</div>
<!-- ... -->
</div>
I have this xpath //div[.//a]
, which selects both div
s.
How to write the xpath which selects the nearest div
of his child(a
). Without link it by that sometag
.
Upvotes: 1
Views: 70
Reputation: 89305
You can try to locate the a
elements first and then select nearest ancestor div
from there:
//a/ancestor::div[1]
Upvotes: 2