Puppeteer Wait Until Page Is Completely Loaded

JS Puppeteer wait for page load to complete

There is absolutely no need to use page.on('load') to find if page loaded.

You can use the,

  • waitUntil option on .goto call.
  • waitForSelector function for specific selector.

Usage,

await page.goto('http://www.produktresume.dk/AppBuilder/search?page=0', {waitUntil: 'networkidle0'});
await page.waitForSelector("#wrapper"); // Found on the page source code, wait for this to appear
// the rest is just as usual
const drugs = await page
.evaluate(() =>
[...document.querySelectorAll('div.entity-link')].map(item => item)
)
.catch(err => console.log(err))
console.log(drugs[0])

Make sure to use await for the .evaluate call.

Waiting for site to fully load

Check my answer at: https://stackoverflow.com/a/57677369/10251383

Try this options with your page.goto():

await page.goto(url, { waitUntil: 'load' });
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.goto(url, { waitUntil: 'networkidle0' });
await page.goto(url, { waitUntil: 'networkidle2' });


Related Topics



Leave a reply



Submit