Reputation: 43
suppose my HTML structure is :
Parent div has 4 child and i need to click on the child div.Is this following<div class='parent'> <a class="child"> PI </a> <div class="child>CP </div> <a class="child>A </a> <a class="child>B </a> </div>
//a[contains(text(),'A')]/preceding-sibling::div[contains(text(),'CP')]
Upvotes: 0
Views: 2684
Reputation: 16095
Your XPath is valid. The preceding-sibling
axis selector:
Indicates all the nodes that have the same parent as the context node and appear before the context node in the source document. If the context node is an attribute node or namespace node, the
preceding-sibling
axis is empty
Same for following-sibling
, except of course, it:
Indicates all the nodes that have the same parent as the context node and appear after the context node in the source document.
Sources:
Upvotes: 2