Skip to content

Commit f6fec27

Browse files
committed
docs(core-concepts): add selectors and auto-wait sections
1 parent 92a4c70 commit f6fec27

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

docs/core-concepts.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,60 @@ frames can be accessed for interactions inside the frame.
8888

8989
```js
9090
// To interact with elements in an iframe
91-
const frame = page.frame('frame-name');
92-
await frame.fill('#username-input');
91+
const frame = page.frame('frame-login');
92+
await frame.fill('#username-input', 'John');
9393
```
9494

9595
<br/>
9696

9797
## Selectors
9898

99+
Playwright APIs that interact with elements accept selectors as the first argument, used to search for the element. Playwright can search for elements with CSS selectors, XPath, HTML attributes like `id`, `data-test-id` and text content.
100+
101+
Note that all selectors except for XPath pierce shadow DOM automatically.
102+
103+
```js
104+
// Auto-detected CSS notation
105+
await page.click('div');
106+
107+
// Explicit CSS notation
108+
await page.click('css=div');
109+
110+
// Auto-detected XPath notation
111+
await page.click('xpath=//html/body/div');
112+
113+
// Explicit XPath notation
114+
await page.click('//html/body/div');
115+
116+
// Auto-detected text notation
117+
await page.click('"Login"');
118+
119+
// Explicit text notation
120+
await page.click('text="Login"');
121+
```
122+
123+
Selectors using different engines can be combined using the `>>` separator. Learn more about selectors and selector engines [here](./selectors.md).
124+
99125
<br/>
100126

101127
## Auto-waiting
102128

129+
Actions like `click` and `fill` auto-wait for the element to be visible and actionable. For example, click will:
130+
- wait for element with given selector to be in DOM
131+
- wait for it to become displayed, i.e. not `display:none`,
132+
- wait for it to stop moving, for example, until css transition finishes
133+
- scroll the element into view
134+
- wait for it to receive pointer events at the action point, for example, waits until element becomes non-obscured by other elements
135+
136+
137+
```js
138+
// Will wait for #search element to be in DOM
139+
await page.fill('#search', 'query');
140+
141+
// Will wait for it to stop animating and accept clicks
142+
await page.click('#search');
143+
```
144+
103145
<br/>
104146

105147
## Execution contexts

0 commit comments

Comments
 (0)