docs: add python snippets for api classes (follow up) (#5018)
This commit is contained in:
Родитель
3ed9f2d63e
Коммит
1648d23551
|
@ -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)
|
||||
|
|
|
@ -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-%%
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]>
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче