Академический Документы
Профессиональный Документы
Культура Документы
com)
Siblings in Xpath
The nodes in the HTML tree have a hierarchical relationship to each other.The terms parent, child, and sibling are
used to describe the relationships. Parent nodes have children. Children on the same level are called siblings
(brothers or sisters).
The following image illustrates a part of the node tree and the relationship between the nodes:
</body>
</html>
<option>Bangalore</option>
Xpath expression:
//option[text()=’ Bangalore’]
Xpath expression:
//option[text()='Bangalore']/following-sibling::option
following-sibling is used to find the next element present under the same parent (in this example “Chennai”)
following-sibling::htmlTag
By Bhanu Prakash (javagalbhanu@gmail.com)
Xpath expression:
//option[text()='Bangalore']/preceding-sibling::option
preceding-sibling is used to find previous element present under the same parent (in this example “Ahmadabad”)
preceding -sibling::htmlTag
Please Note:
following-sibling will return all the element present next to the specified element under the same parent
preceding-sibling will return all the element present before the specified element under the same parent
Example:
//option[text()=’Ahmadabad’]/following-sibling ::option
//option[text()=’Ahmadabad’]/following-sibling ::option[1]