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
Mobile Safari Sometimes Does Not Trigger the Click Event
Javascript: How to Redirect a Page After Validation
Stop Just One Dropdown Toggle from Closing on Click
React-Native React-Navigation Undefined Is Not an Object (Evaluating 'S.Value.Startswith')
How to Modify Chartjs Tooltip So I Can Add Customized Strings in Tooltips
How to Redirect to Another Page Using Angularjs
Disable Right-Clicking in Html5 Video
Regular Expression Which Allow Only Characters or Space
Why Flatlist Is Not Updating Dynamically in React Native
Sort Json Data Based on Date and Time
How to Instantiate a File Object in JavaScript
Use Lodash to Find Objects in an Array Matches an Id (Complex, Drilldown)
How to Sort Data in Ascending or Descending Order in Reactjs
Remove Everything After Last Backslash