-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(selectors): update structure and add best practices #3817
Conversation
docs/selectors.md
Outdated
Playwright supports multiple selector engines used to query elements in the web page. | ||
|
||
Selector can be used to obtain `ElementHandle` (see [page.$()](api.md#pageselector) for example) or shortcut element operations to avoid intermediate handle (see [page.click()](api.md#pageclickselector-options) for example). | ||
Selectors query elements on the web page for interactions, like [page.click](api.md#pageclickselector-options), and to obtain `ElementHandle` through [page.$](api.md#pageselector). Built-in selectors auto-pierce [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) roots. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 'shadow DOM roots' sounds strange, I'd leave just 'shadow DOM'.
docs/selectors.md
Outdated
- Example: `page.click('div')` is converted to `page.click('css=div')`. | ||
|
||
### Combining selectors | ||
Selectors defined as `engine=body` can be combined with the `>>` token, e.g. `clause1 >> clause2 >> clause3`. When multiple clauses are present, next one is queried relative to the previous one's result. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Short-form selectors can be combined as well:
div >> ../../.. >> "text"
- I'd replace "clause" with "selector" in this section.
docs/selectors.md
Outdated
@@ -28,12 +45,61 @@ document | |||
.querySelector('span[attr=value]') | |||
``` | |||
|
|||
Selector engine name can be prefixed with `*` to capture element that matches the particular clause instead of the last one. For example, `css=article >> text=Hello` captures the element with the text `Hello`, and `*css=article >> text=Hello` (note the `*`) captures the `article` element that contains some element with the text `Hello`. | |||
If a selector needs to include `>>` in the body, it should be escaped inside a string to not be confused with clause separator, e.g. `text="some >> text"`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 'clause separator' -> 'the separator'
docs/selectors.md
Outdated
If a selector needs to include `>>` in the body, it should be escaped inside a string to not be confused with clause separator, e.g. `text="some >> text"`. | ||
|
||
### Intermediate matches | ||
Selector clauses can be prefixed with `*` to capture element that matches a particular clause instead of the last one. For example, `css=article >> text=Hello` captures the element with the text `Hello`, and `*css=article >> text=Hello` (note the `*`) captures the `article` element that contains some element with the text `Hello`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Selector engine name can be prefixed ...."
No description provided.