@@ -1783,14 +1783,14 @@ await browser.close();
1783
1783
1784
1784
``` python async
1785
1785
page = await browser.new_page()
1786
- await page.route(r " ( \. png$ ) | ( \. jpg$ ) " , lambda route : route.abort())
1786
+ await page.route(re.compile( r " ( \. png$ ) | ( \. jpg$ ) " ) , lambda route : route.abort())
1787
1787
await page.goto(" https://example.com" )
1788
1788
await browser.close()
1789
1789
```
1790
1790
1791
1791
``` python sync
1792
1792
page = browser.new_page()
1793
- page.route(r " ( \. png$ ) | ( \. jpg$ ) " , lambda route : route.abort())
1793
+ page.route(re.compile( r " ( \. png$ ) | ( \. jpg$ ) " ) , lambda route : route.abort())
1794
1794
page.goto(" https://example.com" )
1795
1795
browser.close()
1796
1796
```
@@ -2163,12 +2163,31 @@ Video object associated with this page.
2163
2163
- ` height ` <[ int] > page height in pixels.
2164
2164
2165
2165
## async method: Page.waitForEvent
2166
+ * langs:
2167
+ - alias-python: expect_event
2166
2168
- returns: <[ any] >
2167
2169
2168
- Returns the event data value.
2169
-
2170
2170
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
2171
- value. Will throw an error if the page is closed before the event is fired.
2171
+ value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
2172
+
2173
+ ``` js
2174
+ const [frame , _ ] = await Promise .all ([
2175
+ page .waitForEvent (' framenavigated' ),
2176
+ page .click (' button' )
2177
+ ]);
2178
+ ```
2179
+
2180
+ ``` python async
2181
+ async with page.expect_event(" framenavigated" ) as event_info:
2182
+ await page.click(" button" )
2183
+ frame = await event_info.value
2184
+ ```
2185
+
2186
+ ``` python sync
2187
+ with page.expect_event(" framenavigated" ) as event_info:
2188
+ page.click(" button" )
2189
+ frame = event_info.value
2190
+ ```
2172
2191
2173
2192
### param: Page.waitForEvent.event = %%-wait-for-event-event-%%
2174
2193
@@ -2329,11 +2348,13 @@ Shortcut for main frame's [`method: Frame.waitForLoadState`].
2329
2348
### option: Page.waitForLoadState.timeout = %%-navigation-timeout-%%
2330
2349
2331
2350
## async method: Page.waitForNavigation
2351
+ * langs:
2352
+ * alias-python: expect_navigation
2332
2353
- returns: <[ null] |[ Response] >
2333
2354
2334
- Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
2335
- last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will
2336
- resolve with ` null ` .
2355
+ Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the navigation
2356
+ will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to
2357
+ History API usage, the navigation will resolve with ` null ` .
2337
2358
2338
2359
This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly
2339
2360
cause the page to navigate. e.g. The click target has an ` onclick ` handler that triggers navigation from a ` setTimeout ` .
@@ -2372,6 +2393,8 @@ Shortcut for main frame's [`method: Frame.waitForNavigation`].
2372
2393
### option: Page.waitForNavigation.waitUntil = %%-navigation-wait-until-%%
2373
2394
2374
2395
## async method: Page.waitForRequest
2396
+ * langs:
2397
+ * alias-python: expect_request
2375
2398
- returns: <[ Request] >
2376
2399
2377
2400
Waits for the matching request and returns it.
@@ -2383,15 +2406,23 @@ return firstRequest.url();
2383
2406
```
2384
2407
2385
2408
``` python async
2386
- first_request = await page.wait_for_request(" http://example.com/resource" )
2387
- final_request = await page.wait_for_request(lambda request : request.url == " http://example.com" and request.method == " get" )
2388
- return first_request.url
2409
+ async with page.expect_request(" http://example.com/resource" ) as first:
2410
+ await page.click(' button' )
2411
+ first_request = await first.value
2412
+
2413
+ async with page.expect_request(lambda request : request.url == " http://example.com" and request.method == " get" ) as second:
2414
+ await page.click(' img' )
2415
+ second_request = await second.value
2389
2416
```
2390
2417
2391
2418
``` python sync
2392
- first_request = page.wait_for_request(" http://example.com/resource" )
2393
- final_request = page.wait_for_request(lambda request : request.url == " http://example.com" and request.method == " get" )
2394
- return first_request.url
2419
+ with page.expect_request(" http://example.com/resource" ) as first:
2420
+ page.click(' button' )
2421
+ first_request = first.value
2422
+
2423
+ with page.expect_request(lambda request : request.url == " http://example.com" and request.method == " get" ) as second:
2424
+ page.click(' img' )
2425
+ second_request = second.value
2395
2426
```
2396
2427
2397
2428
``` js
@@ -2410,6 +2441,8 @@ Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable t
2410
2441
changed by using the [ ` method: Page.setDefaultTimeout ` ] method.
2411
2442
2412
2443
## async method: Page.waitForResponse
2444
+ * langs:
2445
+ * alias-python: expect_response
2413
2446
- returns: <[ Response] >
2414
2447
2415
2448
Returns the matched response.
0 commit comments