Page.expect_request Waits for the matching request and returns it. See [waiting for event](https://playwright.dev/python/docs/events#waiting-for-event) for more details about events. **Usage** ```py async with page.expect_request(\"http://example.com/resour
(
self,
url_or_predicate: typing.Union[
str,
typing.Pattern[str],
typing.Callable[["Request"], typing.Union[bool, typing.Awaitable[bool]]],
],
*,
timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
)
| 13091 | ) |
| 13092 | |
| 13093 | def expect_request( |
| 13094 | self, |
| 13095 | url_or_predicate: typing.Union[ |
| 13096 | str, |
| 13097 | typing.Pattern[str], |
| 13098 | typing.Callable[["Request"], typing.Union[bool, typing.Awaitable[bool]]], |
| 13099 | ], |
| 13100 | *, |
| 13101 | timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None, |
| 13102 | ) -> AsyncEventContextManager["Request"]: |
| 13103 | """Page.expect_request |
| 13104 | |
| 13105 | Waits for the matching request and returns it. See [waiting for event](https://playwright.dev/python/docs/events#waiting-for-event) for more |
| 13106 | details about events. |
| 13107 | |
| 13108 | **Usage** |
| 13109 | |
| 13110 | ```py |
| 13111 | async with page.expect_request(\"http://example.com/resource\") as first: |
| 13112 | await page.get_by_text(\"trigger request\").click() |
| 13113 | first_request = await first.value |
| 13114 | |
| 13115 | # or with a lambda |
| 13116 | async with page.expect_request(lambda request: request.url == \"http://example.com\" and request.method == \"get\") as second: |
| 13117 | await page.get_by_text(\"trigger request\").click() |
| 13118 | second_request = await second.value |
| 13119 | ``` |
| 13120 | |
| 13121 | Parameters |
| 13122 | ---------- |
| 13123 | url_or_predicate : Union[Callable[[Request], Union[bool, typing.Awaitable[bool]]], Pattern[str], str] |
| 13124 | Request URL string, regex or predicate receiving `Request` object. When a `baseURL` via the context options was |
| 13125 | provided and the passed URL is a path, it gets merged via the |
| 13126 | [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. |
| 13127 | timeout : Union[float, None] |
| 13128 | Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can |
| 13129 | be changed by using the `page.set_default_timeout()` method. |
| 13130 | |
| 13131 | Returns |
| 13132 | ------- |
| 13133 | EventContextManager[Request] |
| 13134 | """ |
| 13135 | |
| 13136 | return AsyncEventContextManager( |
| 13137 | self._impl_obj.expect_request( |
| 13138 | urlOrPredicate=self._wrap_handler(url_or_predicate), |
| 13139 | timeout=to_milliseconds(timeout), |
| 13140 | ).future |
| 13141 | ) |
| 13142 | |
| 13143 | def expect_request_finished( |
| 13144 | self, |
nothing calls this directly
no test coverage detected