Descendant Selectors¶
A descendant selector
uniquely identifies an element (descendant) relative to another element (ancestor). The
targeted descendant need not be a direct descendant of the given ancestor.
A descendant selector
may be used to target an element by means of an ancestor > descendant relationship which
is otherwise not possible or impractical using a single CSS- or XPath-based selector
.
Syntax¶
{selector} >> {selector}[ >> {selector}]
----------------------------------------
selector:
<selector>
Examples¶
$"#ancestor" >> $"#descendant" |
CSS selector descendant within the scope of a CSS selector ancestor. |
---|---|
$"//*[@id='ancestor']" >> $"//*[@id='descendant']" |
XPath expression descendant within the scope of an XPath expression ancestor. |
$"#ancestor" >> $"//*[@id='descendant']" |
XPath expression descendant within the scope of a CSS selector ancestor. |
$"//*[@id='ancestor']" >> $"#descendant" |
CSS selector descendant within the scope of an XPath expression ancestor. |
$"#grandparent" >> $"#parent" >> $"#child" |
Targeting the child of a parent which itself is the child of a grandparent. |
$".grandparent" >> $".parent":2 >> $".child":4 |
Targeting the fourth child of the second child of the grandparent. |