Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer wait page load after form submit

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?

like image 610
redochka Avatar asked Oct 26 '17 07:10

redochka


People also ask

How to wait for page load in Puppeteer?

To wait until page is completely loaded with Puppeteer and JavaScript, we call goto with an object with the waitUntil property. await page. goto(url, { waitUntil: "domcontentloaded" }); to call page.

How do you use a puppeteer to click a button?

How to click on a button using puppeteer. click() is used to click on any element or button in the puppeteer. the only challenging thing with this is finding the element. Once you got the element just fire the click() function.


2 Answers

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

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

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

like image 180
Md. Abu Taher Avatar answered Sep 28 '22 21:09

Md. Abu Taher


await page.waitForNavigation(); 
like image 31
redochka Avatar answered Sep 28 '22 19:09

redochka