waitForNavigation method
This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly cause the page to navigate. Consider this example:
await Future.wait([
// The future completes after navigation has finished
page.waitForNavigation(),
// Clicking the link will indirectly cause a navigation
page.click('a.my-link'),
]);
NOTE Usage of the History API to change the URL is considered a navigation.
Shortcut for page.mainFrame.waitForNavigation
.
Parameters:
timeout
Maximum navigation time in milliseconds, defaults to 30 seconds, pass Duration.zero to disable timeout. The default value can be changed by using the Page.defaultNavigationTimeout or Page.defaultTimeout properties.wait
When to consider navigation succeeded, defaults to Until.load. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:- Until.load - consider navigation to be finished when the
load
event is fired. - Until.domContentLoaded - consider navigation to be finished when the
DOMContentLoaded
event is fired. - Until.networkIdle - consider navigation to be finished when there
are no more than 0 network connections for at least
500
ms. - Until.networkAlmostIdle - consider navigation to be finished when
there are no more than 2 network connections for at least
500
ms.
- Until.load - consider navigation to be finished when the
Returns: Future which resolves to 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 usage, the navigation will resolve with null
.
Implementation
Future<Response> waitForNavigation({Duration? timeout, Until? wait}) {
return mainFrame.waitForNavigation(timeout: timeout, wait: wait);
}