Skip to main content
Version: 23.10.1

Page.waitForNavigation() 方法

¥Page.waitForNavigation() method

等待页面导航到新 URL 或重新加载。当你运行将间接导致页面导航的代码时,它非常有用。

¥Waits for the page to navigate to a new URL or to reload. It is useful when you run code that will indirectly cause the page to navigate.

签名

¥Signature

class Page {
waitForNavigation(options?: WaitForOptions): Promise<HTTPResponse | null>;
}

参数

¥Parameters

范围

类型

描述

options

WaitForOptions

(可选的)导航参数可能具有以下属性:

Returns:

Promise<HTTPResponse | null>

解析为主资源响应的 Promise

¥A Promise which resolves to the main resource response.

  • 如果存在多个重定向,导航将使用最后一个重定向的响应进行解析。* 如果导航到不同的锚点或由于历史 API 使用而导航,则导航将解析为 null

    ¥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.

备注

¥Remarks

使用 历史 API 更改 URL 被视为导航。

¥Usage of the History API to change the URL is considered a navigation.

示例

¥Example

const [response] = await Promise.all([
page.waitForNavigation(), // The promise resolves after navigation has finished
page.click('a.my-link'), // Clicking the link will indirectly cause a navigation
]);