0
0
Selenium Javatesting~5 mins

XPath axes (parent, following-sibling, preceding) in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the XPath axis parent:: select?
The parent:: axis selects the parent node of the current node in the XML or HTML document tree.
Click to reveal answer
beginner
How does following-sibling:: axis work in XPath?
The following-sibling:: axis selects all sibling nodes that come after the current node at the same tree level.
Click to reveal answer
intermediate
What is the difference between preceding:: and preceding-sibling:: axes?
preceding:: selects all nodes that come before the current node in the document, regardless of level, while preceding-sibling:: selects only sibling nodes before the current node at the same level.
Click to reveal answer
beginner
Write an XPath to select the parent of a <span> element with id 'price'.
XPath: //span[@id='price']/parent::* selects the parent node of the <span> with id 'price'.
Click to reveal answer
intermediate
In Selenium Java, how would you locate the next sibling <div> after a <h2> element with text 'Title'?
Use XPath: //h2[text()='Title']/following-sibling::div[1] to find the first <div> sibling after the <h2> with text 'Title'.
Click to reveal answer
Which XPath axis selects the parent node of the current node?
Apreceding::
Bparent::
Cfollowing-sibling::
Dchild::
What does following-sibling::div[1] select?
AThe first <code>&lt;div&gt;</code> sibling after the current node
BThe first <code>&lt;div&gt;</code> sibling before the current node
CThe parent <code>&lt;div&gt;</code> node
DAll <code>&lt;div&gt;</code> descendants
Which axis selects all nodes before the current node regardless of level?
Apreceding::
Bfollowing-sibling::
Cpreceding-sibling::
Dparent::
In XPath, how do you select the parent of the current node?
Achild::*
Bfollowing::*
Cancestor::*
Dparent::*
Which XPath axis would you use to find siblings before the current node?
Aparent::
Bfollowing-sibling::
Cpreceding-sibling::
Dchild::
Explain how the XPath axes parent::, following-sibling::, and preceding:: differ in selecting nodes.
Think about the direction and level of nodes each axis selects.
You got /3 concepts.
    Write an example XPath using following-sibling:: to select the next sibling <li> after a <li> with class 'active'.
    Use the axis with an index to get the first following sibling.
    You got /2 concepts.