Skip to main content
Version: 24.38.0

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

范围

🌐 Parameter

类型

🌐 Type

描述

🌐 Description

options

等待选项

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

🌐 (Optional) Navigation parameters which might have the following properties:

返回:

Promise<HTTPResponse | null>

一个 Promise,它解析为主资源响应。

🌐 A Promise which resolves to the main resource response.

  • 如果存在多个重定向,导航将以最后一次重定向的响应为准。- 如果导航到不同的锚点或由于使用 History API 导致导航,导航将以 null 为准。

附注

🌐 Remarks

使用 History 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
]);