Selector syntax
Selector syntax
This page covers core selector patterns supported by the translator.
Basic selectors
- Element selector:
p - Universal selector:
* - ID selector:
#hero - Class selector:
.selected - Combined selector:
nav.c-menu.main-selection
Combinators
- Descendant:
article p - Child:
form>label - Adjacent sibling:
header + div - General sibling:
header ~ div
Examples
| CSS | XPath |
|---|---|
main article p |
.//main//article//p |
form>label>input |
.//form/label/input |
.content#content-element |
.//*[contains(concat(' ',normalize-space(@class),' '),' content ')][@id='content-element'] |
main header ~ div.details |
.//main//header/following-sibling::div[contains(concat(' ',normalize-space(@class),' '),' details ')] |
Notes
- Whitespace around
>/+/~is optional. - Multiple class selectors can be chained (
.a.b.c). - Multiple selectors can be grouped with commas (
h1, p, a.button).
Continue learning about attribute selectors.