Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs: add python snippets for api classes (follow up) (#5018)

Pavel Feldman1648d235516d
diff --git a/docs/src/api/class-accessibility.md b/docs/src/api/class-accessibility.md
index a5680c8406..ff6b0958b8 100644
--- a/docs/src/api/class-accessibility.md
+++ b/docs/src/api/class-accessibility.md
@@ -93,7 +93,7 @@ def find_focused_node(node):
for child in (node.get("children") or []):
found_node = find_focused_node(child)
return found_node
- return null
+ return None
snapshot = await page.accessibility.snapshot()
node = find_focused_node(snapshot)
@@ -108,7 +108,7 @@ def find_focused_node(node):
for child in (node.get("children") or []):
found_node = find_focused_node(child)
return found_node
- return null
+ return None
snapshot = page.accessibility.snapshot()
node = find_focused_node(snapshot)
diff --git a/docs/src/api/class-browser.md b/docs/src/api/class-browser.md
index ba6ea0148b..7a4772d101 100644
--- a/docs/src/api/class-browser.md
+++ b/docs/src/api/class-browser.md
@@ -110,21 +110,21 @@ Creates a new browser context. It won't share cookies/cache with other browser c
```
```python async
- browser = await playwright.firefox.launch() # or "chromium" or "webkit".
- # create a new incognito browser context.
- context = await browser.new_context()
- # create a new page in a pristine context.
- page = await context.new_page()
- await page.goto("https://example.com")
+browser = await playwright.firefox.launch() # or "chromium" or "webkit".
+# create a new incognito browser context.
+context = await browser.new_context()
+# create a new page in a pristine context.
+page = await context.new_page()
+await page.goto("https://example.com")
```
```python sync
- browser = playwright.firefox.launch() # or "chromium" or "webkit".
- # create a new incognito browser context.
- context = browser.new_context()
- # create a new page in a pristine context.
- page = context.new_page()
- page.goto("https://example.com")
+browser = playwright.firefox.launch() # or "chromium" or "webkit".
+# create a new incognito browser context.
+context = browser.new_context()
+# create a new page in a pristine context.
+page = context.new_page()
+page.goto("https://example.com")
```
### option: Browser.newContext.-inline- = %%-shared-context-params-list-%%
diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md
index 9b4e5f3466..0ae739a63f 100644
--- a/docs/src/api/class-browsercontext.md
+++ b/docs/src/api/class-browsercontext.md
@@ -567,7 +567,8 @@ await browser.close();
```python async
context = await browser.new_context()
page = await context.new_page()
-await context.route(r"(\.png$)|(\.jpg$)", lambda page = await context.new_page()
+await context.route(r"(\.png$)|(\.jpg$)", lambda route => route.abort())
+page = await context.new_page()
await page.goto("https://example.com")
await browser.close()
```
@@ -575,7 +576,8 @@ await browser.close()
```python sync
context = browser.new_context()
page = context.new_page()
-context.route(r"(\.png$)|(\.jpg$)", lambda page = await context.new_page()
+context.route(r"(\.png$)|(\.jpg$)", lambda route => route.abort())
+page = await context.new_page()
page = context.new_page()
page.goto("https://example.com")
browser.close()
diff --git a/docs/src/api/class-dialog.md b/docs/src/api/class-dialog.md
index a2995b70ac..1adaa7844b 100644
--- a/docs/src/api/class-dialog.md
+++ b/docs/src/api/class-dialog.md
@@ -48,7 +48,7 @@ from playwright.sync_api import sync_playwright
def handle_dialog(dialog):
print(dialog.message)
- await dialog.dismiss()
+ dialog.dismiss()
def run(playwright):
chromium = playwright.chromium
diff --git a/docs/src/api/class-elementhandle.md b/docs/src/api/class-elementhandle.md
index b09555ea5c..76709eb0f7 100644
--- a/docs/src/api/class-elementhandle.md
+++ b/docs/src/api/class-elementhandle.md
@@ -547,31 +547,31 @@ element, the method throws an error.
```js
// single selection matching the value
-handle.selectOption('select#colors', 'blue');
+handle.selectOption('blue');
// single selection matching the label
-handle.selectOption('select#colors', { label: 'Blue' });
+handle.selectOption({ label: 'Blue' });
// multiple selection
-handle.selectOption('select#colors', ['red', 'green', 'blue']);
+handle.selectOption(['red', 'green', 'blue']);
```
```python async
# single selection matching the value
-await handle.select_option("select#colors", "blue")
+await handle.select_option("blue")
# single selection matching the label
-await handle.select_option("select#colors", label="blue")
+await handle.select_option(label="blue")
# multiple selection
-await handle.select_option("select#colors", value=["red", "green", "blue"])
+await handle.select_option(value=["red", "green", "blue"])
```
```python sync
# single selection matching the value
-handle.select_option("select#colors", "blue")
+handle.select_option("blue")
# single selection matching both the label
-handle.select_option("select#colors", label="blue")
+handle.select_option(label="blue")
# multiple selection
-handle.select_option("select#colors", value=["red", "green", "blue"])
+handle.select_option(value=["red", "green", "blue"])
```
```python sync
diff --git a/docs/src/api/class-frame.md b/docs/src/api/class-frame.md
index d17894d48b..c660e9140f 100644
--- a/docs/src/api/class-frame.md
+++ b/docs/src/api/class-frame.md
@@ -1046,7 +1046,7 @@ async def run(playwright):
webkit = playwright.webkit
browser = await webkit.launch()
page = await browser.new_page()
- watch_dog = page.main_frame.wait_for_function("() => window.innerWidth < 100")
+ watch_dog = asyncio.create_task(page.main_frame.wait_for_function("() => window.innerWidth < 100")
await page.set_viewport_size({"width": 50, "height": 50})
await watch_dog
await browser.close()
@@ -1057,22 +1057,6 @@ async def main():
asyncio.run(main())
```
-```python sync
-from playwright.sync_api import sync_playwright
-
-def run(playwright):
- webkit = playwright.webkit
- browser = await webkit.launch()
- page = await browser.new_page()
- watch_dog = page.main_frame.wait_for_function("() => window.innerWidth < 100")
- await page.set_viewport_size({"width": 50, "height": 50})
- await watch_dog
- await browser.close()
-
-with sync_playwright() as playwright:
- run(playwright)
-```
-
To pass an argument to the predicate of `frame.waitForFunction` function:
```js
diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md
index 6be389fcdc..459612f106 100644
--- a/docs/src/api/class-page.md
+++ b/docs/src/api/class-page.md
@@ -916,7 +916,7 @@ Returns the value of the [`param: pageFunction`] invocation as in-page object (J
The only difference between [`method: Page.evaluate`] and [`method: Page.evaluateHandle`] is that [`method: Page.evaluateHandle`] returns in-page
object (JSHandle).
-If the function passed to the [`method: Page.evaluateHandle`] returns a [Promise], then [`method:Ppage.EvaluateHandle`] would wait for the
+If the function passed to the [`method: Page.evaluateHandle`] returns a [Promise], then [`method: Page.evaluateHandle`] would wait for the
promise to resolve and return its value.
```js
diff --git a/docs/src/api/class-playwright.md b/docs/src/api/class-playwright.md
index 91948d6174..d642e6f7da 100644
--- a/docs/src/api/class-playwright.md
+++ b/docs/src/api/class-playwright.md
@@ -48,9 +48,6 @@ with sync_playwright() as playwright:
run(playwright)
```
-By default, the `playwright` NPM package automatically downloads browser executables during installation. The
-`playwright-core` NPM package can be used to skip automatic downloads.
-
## property: Playwright.chromium
- type: <[BrowserType]>
diff --git a/docs/src/api/class-request.md b/docs/src/api/class-request.md
index 06ae9523bd..97decd69f1 100644
--- a/docs/src/api/class-request.md
+++ b/docs/src/api/class-request.md
@@ -32,7 +32,7 @@ page.on('requestfailed', request => {
```
```py
-page.on("requestfailed", lambda: request => print(request.url + " " + request.failure)
+page.on("requestfailed", lambda request: print(request.url + " " + request.failure))
```
## method: Request.frame
diff --git a/types/types.d.ts b/types/types.d.ts
index aedb0717cb..fcc0ed8d86 100644
--- a/types/types.d.ts
+++ b/types/types.d.ts
@@ -131,7 +131,9 @@ export interface Page {
*
* If the function passed to the
* [page.evaluateHandle(…)](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageevaluatehandle) returns a
- * [Promise], then [`method:Ppage.EvaluateHandle`] would wait for the promise to resolve and return its value.
+ * [Promise], then
+ * [page.evaluateHandle(…)](https://github.com/microsoft/playwright/blob/master/docs/api.md#pageevaluatehandle) would wait
+ * for the promise to resolve and return its value.
*
* ```js
* const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));
@@ -5940,13 +5942,13 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
*
* ```js
* // single selection matching the value
- * handle.selectOption('select#colors', 'blue');
+ * handle.selectOption('blue');
*
* // single selection matching the label
- * handle.selectOption('select#colors', { label: 'Blue' });
+ * handle.selectOption({ label: 'Blue' });
*
* // multiple selection
- * handle.selectOption('select#colors', ['red', 'green', 'blue']);
+ * handle.selectOption(['red', 'green', 'blue']);
* ```
*
* @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