Page.waitForResponse() 方法
¥Page.waitForResponse() method
签名
¥Signature
class Page {
waitForResponse(
urlOrPredicate: string | AwaitablePredicate<HTTPResponse>,
options?: WaitTimeoutOptions,
): Promise<HTTPResponse>;
}
参数
¥Parameters
范围 | 类型 | 描述 |
|---|---|---|
urlOrPredicate | 要等待的 URL 或谓词。 | |
options | (可选的)可选等待参数 |
Returns:
Promise<HTTPResponse>
解析为匹配响应的 Promise。
¥Promise which resolves to the matched response.
备注
¥Remarks
可选参数有:
¥Optional Parameter have:
-
timeout:最大等待时间(以毫秒为单位),默认为30秒,通过0禁用超时。可以使用 Page.setDefaultTimeout() 方法更改默认值。¥
timeout: Maximum wait time in milliseconds, defaults to30seconds, pass0to disable the timeout. The default value can be changed by using the Page.setDefaultTimeout() method.
示例
¥Example
const firstResponse = await page.waitForResponse(
'https://example.com/resource',
);
const finalResponse = await page.waitForResponse(
response =>
response.url() === 'https://example.com' && response.status() === 200,
);
const finalResponse = await page.waitForResponse(async response => {
return (await response.text()).includes('<html>');
});
return finalResponse.ok();