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

Method expect_navigation

playwright/async_api/_generated.py:12995–13059  ·  view source on GitHub ↗

Page.expect_navigation Waits for the main 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

(
        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

12993 )
12994
12995 def expect_navigation(
12996 self,
12997 *,
12998 url: typing.Optional[
12999 typing.Union[str, typing.Pattern[str], typing.Callable[[str], bool]]
13000 ] = None,
13001 wait_until: typing.Optional[
13002 Literal["commit", "domcontentloaded", "load", "networkidle"]
13003 ] = None,
13004 timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
13005 ) -> AsyncEventContextManager["Response"]:
13006 """Page.expect_navigation
13007
13008 Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the
13009 navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or
13010 navigation due to History API usage, the navigation will resolve with `null`.
13011
13012 **Usage**
13013
13014 This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will
13015 indirectly cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from
13016 a `setTimeout`. Consider this example:
13017
13018 ```py
13019 async with page.expect_navigation():
13020 # This action triggers the navigation after a timeout.
13021 await page.get_by_text(\"Navigate after timeout\").click()
13022 # Resolves after navigation has finished
13023 ```
13024
13025 **NOTE** Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL
13026 is considered a navigation.
13027
13028 Parameters
13029 ----------
13030 url : Union[Callable[[str], bool], Pattern[str], str, None]
13031 A glob pattern, regex pattern, or predicate receiving [URL] to match while waiting for the navigation. Note that if
13032 the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly
13033 equal to the string.
13034 wait_until : Union["commit", "domcontentloaded", "load", "networkidle", None]
13035 When to consider operation succeeded, defaults to `load`. Events can be either:
13036 - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
13037 - `'load'` - consider operation to be finished when the `load` event is fired.
13038 - `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for
13039 at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
13040 - `'commit'` - consider operation to be finished when network response is received and the document started
13041 loading.
13042 timeout : Union[float, None]
13043 Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can
13044 be changed by using the `browser_context.set_default_navigation_timeout()`,
13045 `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or
13046 `page.set_default_timeout()` methods.
13047
13048 Returns
13049 -------
13050 EventContextManager[Response]
13051 """
13052

Callers 1

expect_navigationMethod · 0.45

Calls 3

to_millisecondsFunction · 0.90
_wrap_handlerMethod · 0.45

Tested by

no test coverage detected