waitForNavigation hanging, even though page was loaded
According to Puppeteer documentation proper pattern for clicking on submit and waiting for navigation is like this:
await Promise.all([
page.waitForNavigation({ waitUntil: 'load' }),
page.click('[type=submit]'),
]);
Adding to the answer of Everettss, I would like to present a more modern code. Basically instead of doing any operation and calling waitFornavigation
, the motive is to do the other way around. Something like this:
//Get the promise which isn't resolved yet
const navigationPromise = page.waitForNavigation();
//Perform the activity (Click, Goto etc). Note that the link is any valid url
await page.goto(link);
//wait until the navigationPromise resolves
await navigationPromise;
This helps to avoid race condition as per this discussion
This code makes use of async/await which is much more readable than promise-based code