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?
✗ Incorrect
The
parent:: axis selects the parent node of the current node.What does
following-sibling::div[1] select?✗ Incorrect
It selects the first
<div> sibling that comes after the current node.Which axis selects all nodes before the current node regardless of level?
✗ Incorrect
preceding:: selects all nodes before the current node in the document, regardless of their position in the tree.In XPath, how do you select the parent of the current node?
✗ Incorrect
parent::* selects the parent node of the current node.Which XPath axis would you use to find siblings before the current node?
✗ Incorrect
preceding-sibling:: selects sibling nodes that come before the current node.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.