Puppeteer wait page load after form submit

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

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'}); 

How to wait for page load with puppeteer?

回答1:

You can wait for navigation asynchronously to avoid getting null on redirection,

await Promise.all([       page.click("button[type=submit]"),       page.waitForNavigation({ waitUntil: 'networkidle0' }), ]); 

This will help you if the page.click already triggers a navigation.



回答2:

await page.waitForNavigation(); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!