Skip to content

Commit 1648d23

Browse files
authored
docs: add python snippets for api classes (follow up) (#5018)
1 parent 3ed9f2d commit 1648d23

10 files changed

+37
-52
lines changed

docs/src/api/class-accessibility.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def find_focused_node(node):
9393
for child in (node.get("children") or []):
9494
found_node = find_focused_node(child)
9595
return found_node
96-
return null
96+
return None
9797

9898
snapshot = await page.accessibility.snapshot()
9999
node = find_focused_node(snapshot)
@@ -108,7 +108,7 @@ def find_focused_node(node):
108108
for child in (node.get("children") or []):
109109
found_node = find_focused_node(child)
110110
return found_node
111-
return null
111+
return None
112112

113113
snapshot = page.accessibility.snapshot()
114114
node = find_focused_node(snapshot)

docs/src/api/class-browser.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,21 @@ Creates a new browser context. It won't share cookies/cache with other browser c
110110
```
111111

112112
```python async
113-
browser = await playwright.firefox.launch() # or "chromium" or "webkit".
114-
# create a new incognito browser context.
115-
context = await browser.new_context()
116-
# create a new page in a pristine context.
117-
page = await context.new_page()
118-
await page.goto("https://example.com")
113+
browser = await playwright.firefox.launch() # or "chromium" or "webkit".
114+
# create a new incognito browser context.
115+
context = await browser.new_context()
116+
# create a new page in a pristine context.
117+
page = await context.new_page()
118+
await page.goto("https://example.com")
119119
```
120120

121121
```python sync
122-
browser = playwright.firefox.launch() # or "chromium" or "webkit".
123-
# create a new incognito browser context.
124-
context = browser.new_context()
125-
# create a new page in a pristine context.
126-
page = context.new_page()
127-
page.goto("https://example.com")
122+
browser = playwright.firefox.launch() # or "chromium" or "webkit".
123+
# create a new incognito browser context.
124+
context = browser.new_context()
125+
# create a new page in a pristine context.
126+
page = context.new_page()
127+
page.goto("https://example.com")
128128
```
129129

130130
### option: Browser.newContext.-inline- = %%-shared-context-params-list-%%

docs/src/api/class-browsercontext.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,15 +567,17 @@ await browser.close();
567567
```python async
568568
context = await browser.new_context()
569569
page = await context.new_page()
570-
await context.route(r"(\.png$)|(\.jpg$)", lambda page = await context.new_page()
570+
await context.route(r"(\.png$)|(\.jpg$)", lambda route => route.abort())
571+
page = await context.new_page()
571572
await page.goto("https://example.com")
572573
await browser.close()
573574
```
574575

575576
```python sync
576577
context = browser.new_context()
577578
page = context.new_page()
578-
context.route(r"(\.png$)|(\.jpg$)", lambda page = await context.new_page()
579+
context.route(r"(\.png$)|(\.jpg$)", lambda route => route.abort())
580+
page = await context.new_page()
579581
page = context.new_page()
580582
page.goto("https://example.com")
581583
browser.close()

docs/src/api/class-dialog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ from playwright.sync_api import sync_playwright
4848

4949
def handle_dialog(dialog):
5050
print(dialog.message)
51-
await dialog.dismiss()
51+
dialog.dismiss()
5252

5353
def run(playwright):
5454
chromium = playwright.chromium

docs/src/api/class-elementhandle.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -547,31 +547,31 @@ element, the method throws an error.
547547

548548
```js
549549
// single selection matching the value
550-
handle.selectOption('select#colors', 'blue');
550+
handle.selectOption('blue');
551551

552552
// single selection matching the label
553-
handle.selectOption('select#colors', { label: 'Blue' });
553+
handle.selectOption({ label: 'Blue' });
554554

555555
// multiple selection
556-
handle.selectOption('select#colors', ['red', 'green', 'blue']);
556+
handle.selectOption(['red', 'green', 'blue']);
557557
```
558558

559559
```python async
560560
# single selection matching the value
561-
await handle.select_option("select#colors", "blue")
561+
await handle.select_option("blue")
562562
# single selection matching the label
563-
await handle.select_option("select#colors", label="blue")
563+
await handle.select_option(label="blue")
564564
# multiple selection
565-
await handle.select_option("select#colors", value=["red", "green", "blue"])
565+
await handle.select_option(value=["red", "green", "blue"])
566566
```
567567

568568
```python sync
569569
# single selection matching the value
570-
handle.select_option("select#colors", "blue")
570+
handle.select_option("blue")
571571
# single selection matching both the label
572-
handle.select_option("select#colors", label="blue")
572+
handle.select_option(label="blue")
573573
# multiple selection
574-
handle.select_option("select#colors", value=["red", "green", "blue"])
574+
handle.select_option(value=["red", "green", "blue"])
575575
```
576576

577577
```python sync

docs/src/api/class-frame.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ async def run(playwright):
10461046
webkit = playwright.webkit
10471047
browser = await webkit.launch()
10481048
page = await browser.new_page()
1049-
watch_dog = page.main_frame.wait_for_function("() => window.innerWidth < 100")
1049+
watch_dog = asyncio.create_task(page.main_frame.wait_for_function("() => window.innerWidth < 100")
10501050
await page.set_viewport_size({"width": 50, "height": 50})
10511051
await watch_dog
10521052
await browser.close()
@@ -1057,22 +1057,6 @@ async def main():
10571057
asyncio.run(main())
10581058
```
10591059

1060-
```python sync
1061-
from playwright.sync_api import sync_playwright
1062-
1063-
def run(playwright):
1064-
webkit = playwright.webkit
1065-
browser = await webkit.launch()
1066-
page = await browser.new_page()
1067-
watch_dog = page.main_frame.wait_for_function("() => window.innerWidth < 100")
1068-
await page.set_viewport_size({"width": 50, "height": 50})
1069-
await watch_dog
1070-
await browser.close()
1071-
1072-
with sync_playwright() as playwright:
1073-
run(playwright)
1074-
```
1075-
10761060
To pass an argument to the predicate of `frame.waitForFunction` function:
10771061

10781062
```js

docs/src/api/class-page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ Returns the value of the [`param: pageFunction`] invocation as in-page object (J
916916
The only difference between [`method: Page.evaluate`] and [`method: Page.evaluateHandle`] is that [`method: Page.evaluateHandle`] returns in-page
917917
object (JSHandle).
918918

919-
If the function passed to the [`method: Page.evaluateHandle`] returns a [Promise], then [`method:Ppage.EvaluateHandle`] would wait for the
919+
If the function passed to the [`method: Page.evaluateHandle`] returns a [Promise], then [`method: Page.evaluateHandle`] would wait for the
920920
promise to resolve and return its value.
921921

922922
```js

docs/src/api/class-playwright.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ with sync_playwright() as playwright:
4848
run(playwright)
4949
```
5050

51-
By default, the `playwright` NPM package automatically downloads browser executables during installation. The
52-
`playwright-core` NPM package can be used to skip automatic downloads.
53-
5451
## property: Playwright.chromium
5552
- type: <[BrowserType]>
5653

docs/src/api/class-request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ page.on('requestfailed', request => {
3232
```
3333

3434
```py
35-
page.on("requestfailed", lambda: request => print(request.url + " " + request.failure)
35+
page.on("requestfailed", lambda request: print(request.url + " " + request.failure))
3636
```
3737

3838
## method: Request.frame

types/types.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export interface Page {
131131
*
132132
* If the function passed to the
133133
* [page.evaluateHandle(…)](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageevaluatehandle) returns a
134-
* [Promise], then [`method:Ppage.EvaluateHandle`] would wait for the promise to resolve and return its value.
134+
* [Promise], then
135+
* [page.evaluateHandle(…)](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageevaluatehandle) would wait
136+
* for the promise to resolve and return its value.
135137
*
136138
* ```js
137139
* const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));
@@ -5940,13 +5942,13 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
59405942
*
59415943
* ```js
59425944
* // single selection matching the value
5943-
* handle.selectOption('select#colors', 'blue');
5945+
* handle.selectOption('blue');
59445946
*
59455947
* // single selection matching the label
5946-
* handle.selectOption('select#colors', { label: 'Blue' });
5948+
* handle.selectOption({ label: 'Blue' });
59475949
*
59485950
* // multiple selection
5949-
* handle.selectOption('select#colors', ['red', 'green', 'blue']);
5951+
* handle.selectOption(['red', 'green', 'blue']);
59505952
* ```
59515953
*
59525954
* @param values Options to select. If the `<select>` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option

0 commit comments

Comments
 (0)