MCPcopy Index your code
hub / github.com/microsoft/playwright-python / expect_navigation

Method expect_navigation

playwright/async_api/_generated.py:3533–3595  ·  view source on GitHub ↗

Frame.expect_navigation Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usag

(
        self,
        *,
        url: typing.Optional[
            typing.Union[str, typing.Pattern[str], typing.Callable[[str], bool]]
        ] = None,
        wait_until: typing.Optional[
            Literal["commit", "domcontentloaded", "load", "networkidle"]
        ] = None,
        timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
    )

Source from the content-addressed store, hash-verified

3531 )
3532
3533 def expect_navigation(
3534 self,
3535 *,
3536 url: typing.Optional[
3537 typing.Union[str, typing.Pattern[str], typing.Callable[[str], bool]]
3538 ] = None,
3539 wait_until: typing.Optional[
3540 Literal["commit", "domcontentloaded", "load", "networkidle"]
3541 ] = None,
3542 timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
3543 ) -> AsyncEventContextManager["Response"]:
3544 """Frame.expect_navigation
3545
3546 Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the
3547 navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or
3548 navigation due to History API usage, the navigation will resolve with `null`.
3549
3550 **Usage**
3551
3552 This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly
3553 cause the frame to navigate. Consider this example:
3554
3555 ```py
3556 async with frame.expect_navigation():
3557 await frame.click(\"a.delayed-navigation\") # clicking the link will indirectly cause a navigation
3558 # Resolves after navigation has finished
3559 ```
3560
3561 **NOTE** Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL
3562 is considered a navigation.
3563
3564 Parameters
3565 ----------
3566 url : Union[Callable[[str], bool], Pattern[str], str, None]
3567 A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if
3568 the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly
3569 equal to the string.
3570 wait_until : Union["commit", "domcontentloaded", "load", "networkidle", None]
3571 When to consider operation succeeded, defaults to `load`. Events can be either:
3572 - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
3573 - `'load'` - consider operation to be finished when the `load` event is fired.
3574 - `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for
3575 at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
3576 - `'commit'` - consider operation to be finished when network response is received and the document started
3577 loading.
3578 timeout : Union[float, None]
3579 Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can
3580 be changed by using the `browser_context.set_default_navigation_timeout()`,
3581 `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or
3582 `page.set_default_timeout()` methods.
3583
3584 Returns
3585 -------
3586 EventContextManager[Response]
3587 """
3588
3589 return AsyncEventContextManager(
3590 self._impl_obj.expect_navigation(

Callers

nothing calls this directly

Calls 4

to_millisecondsFunction · 0.90
expect_navigationMethod · 0.45
_wrap_handlerMethod · 0.45

Tested by

no test coverage detected