表单提交后 Puppeteer 等待页面加载 [英] Puppeteer wait page load after form submit
本文介绍了表单提交后 Puppeteer 等待页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码提交表单,我希望 Puppeteer 在表单提交后等待页面加载.
I submit a form using the following code and i want Puppeteer to wait page load after form submit.
await page.click("button[type=submit]");
//how to wait until the new page loads before taking screenshot?
// i don't want this:
// await page.waitFor(1*1000); //← unwanted workaround
await page.screenshot({path: 'example.png'});
如何使用 puppeteer 等待页面加载?
How to wait for page load with puppeteer?
推荐答案
您可以异步等待导航以避免在重定向时获得 null
,
You can wait for navigation asynchronously to avoid getting null
on redirection,
await Promise.all([
page.click("button[type=submit]"),
page.waitForNavigation({ waitUntil: 'networkidle0' }),
]);
如果 page.click 已触发导航,这将对您有所帮助.
This will help you if the page.click already triggers a navigation.
这篇关于表单提交后 Puppeteer 等待页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文