Skip to content

Commit 4b0d977

Browse files
authored
fix(docs): clarify the single/double quotes usage in text selector (#2002)
1 parent 030c217 commit 4b0d977

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4220,7 +4220,7 @@ Selector has the following format: `engine=body [>> engine=body]*`. Here `engine
42204220

42214221
For convenience, selectors in the wrong format are heuristically converted to the right format:
42224222
- selector starting with `//` is assumed to be `xpath=selector`;
4223-
- selector starting with `"` is assumed to be `text=selector`;
4223+
- selector starting and ending with a quote (either `"` or `'`) is assumed to be `text=selector`;
42244224
- otherwise selector is assumed to be `css=selector`.
42254225

42264226
```js

docs/selectors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Selector engine name can be prefixed with `*` to capture element that matches th
2626

2727
For convenience, selectors in the wrong format are heuristically converted to the right format:
2828
- Selector starting with `//` is assumed to be `xpath=selector`. Example: `page.click('//html')` is converted to `page.click('xpath=//html')`.
29-
- Selector surrounded with quotes (either `"` or `'`) is assumed to be `text=selector`. Example: `page.click('"foo"')` is converted to `page.click('text="foo"')`.
29+
- Selector starting and ending with a quote (either `"` or `'`) is assumed to be `text=selector`. Example: `page.click('"foo"')` is converted to `page.click('text="foo"')`.
3030
- Otherwise, selector is assumed to be `css=selector`. Example: `page.click('div')` is converted to `page.click('css=div')`.
3131

3232
## Examples
@@ -61,7 +61,7 @@ const handle = await divHandle.$('css=span');
6161

6262
### css and css:light
6363

64-
`css` is a default engine - any malformed selector not starting with `//` nor surrounded with quotes is assumed to be a css selector. For example, Playwright converts `page.$('span > button')` to `page.$('css=span > button')`.
64+
`css` is a default engine - any malformed selector not starting with `//` nor starting and ending with a quote is assumed to be a css selector. For example, Playwright converts `page.$('span > button')` to `page.$('css=span > button')`.
6565

6666
`css:light` engine is equivalent to [`Document.querySelector`](https://developer.mozilla.org/en/docs/Web/API/Document/querySelector) and behaves according to the CSS spec. However, it does not pierce shadow roots, which may be inconvenient when working with [Shadow DOM and Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM). For that reason, `css` engine pierces shadow roots. More specifically, every [Descendant combinator](https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator) pierces an arbitrary number of open shadow roots, including the implicit descendant combinator at the start of the selector.
6767

@@ -115,7 +115,7 @@ Text engine finds an element that contains a text node with the passed text. For
115115
- Text body can also be a JavaScript-like regex wrapped in `/` symbols. This means `text=/^\\s*Login$/i` will match `<button> loGIN</button>` with any number of spaces before "Login" and no spaces after.
116116
- Input elements of the type `button` and `submit` are rendered with their value as text, and text engine finds them. For example, `text=Login` matches `<input type=button value="Login">`.
117117

118-
Malformed selector surrounded with quotes (either `"` or `'`) is assumed to be a text selector. For example, Playwright converts `page.click('"Login"')` to `page.click('text="Login"')`.
118+
Malformed selector starting and ending with a quote (either `"` or `'`) is assumed to be a text selector. For example, Playwright converts `page.click('"Login"')` to `page.click('text="Login"')`.
119119

120120
`text` engine open pierces shadow roots similarly to `css`, while `text:light` does not. Text engine first searches for elements in the light dom in the iteration order, and then recursively inside open shadow roots in the iteration order. It does not search inside closed shadow roots or iframes.
121121

0 commit comments

Comments
 (0)