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?
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 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.
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.
await page.waitForNavigation();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With