Page.expect_response Returns the matched response. See [waiting for event](https://playwright.dev/python/docs/events#waiting-for-event) for more details about events. **Usage** ```py async with page.expect_response(\"https://example.com/resource\") as respo
(
self,
url_or_predicate: typing.Union[
str,
typing.Pattern[str],
typing.Callable[["Response"], typing.Union[bool, typing.Awaitable[bool]]],
],
*,
timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
)
| 13173 | ) |
| 13174 | |
| 13175 | def expect_response( |
| 13176 | self, |
| 13177 | url_or_predicate: typing.Union[ |
| 13178 | str, |
| 13179 | typing.Pattern[str], |
| 13180 | typing.Callable[["Response"], typing.Union[bool, typing.Awaitable[bool]]], |
| 13181 | ], |
| 13182 | *, |
| 13183 | timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None, |
| 13184 | ) -> AsyncEventContextManager["Response"]: |
| 13185 | """Page.expect_response |
| 13186 | |
| 13187 | Returns the matched response. See [waiting for event](https://playwright.dev/python/docs/events#waiting-for-event) for more details about |
| 13188 | events. |
| 13189 | |
| 13190 | **Usage** |
| 13191 | |
| 13192 | ```py |
| 13193 | async with page.expect_response(\"https://example.com/resource\") as response_info: |
| 13194 | await page.get_by_text(\"trigger response\").click() |
| 13195 | response = await response_info.value |
| 13196 | return response.ok |
| 13197 | |
| 13198 | # or with a lambda |
| 13199 | async with page.expect_response(lambda response: response.url == \"https://example.com\" and response.status == 200 and response.request.method == \"get\") as response_info: |
| 13200 | await page.get_by_text(\"trigger response\").click() |
| 13201 | response = await response_info.value |
| 13202 | return response.ok |
| 13203 | ``` |
| 13204 | |
| 13205 | Parameters |
| 13206 | ---------- |
| 13207 | url_or_predicate : Union[Callable[[Response], Union[bool, typing.Awaitable[bool]]], Pattern[str], str] |
| 13208 | Request URL string, regex or predicate receiving `Response` object. When a `baseURL` via the context options was |
| 13209 | provided and the passed URL is a path, it gets merged via the |
| 13210 | [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. |
| 13211 | timeout : Union[float, None] |
| 13212 | Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can |
| 13213 | be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. |
| 13214 | |
| 13215 | Returns |
| 13216 | ------- |
| 13217 | EventContextManager[Response] |
| 13218 | """ |
| 13219 | |
| 13220 | return AsyncEventContextManager( |
| 13221 | self._impl_obj.expect_response( |
| 13222 | urlOrPredicate=self._wrap_handler(url_or_predicate), |
| 13223 | timeout=to_milliseconds(timeout), |
| 13224 | ).future |
| 13225 | ) |
| 13226 | |
| 13227 | def expect_websocket( |
| 13228 | self, |
nothing calls this directly
no test coverage detected