How would puppeteer wait for all redirects

Roman picture Roman · Jul 30, 2018 · Viewed 10.2k times · Source

I have a puppeteer project which needs to submit a form and then wait for the next page. The problem is that to get to the next page, the site would make around 3-4 redirects and only then will start loading the actual content.

It seems Puppeteer is getting stuck somewhere in the middle.

How would I go around this?

This is my code:

await page.goto('<url>/Login.html', {'waitUntil': 'networkidle0', timeout: 60000});

await page.click(USERID_SLCT);
await page.keyboard.type(creds.userId);
await page.click(PWD_SLCT);
await page.keyboard.type(creds.pwd);
await page.click(LOGINBTN_SLCT);

await page.waitForNavigation({'waitUntil': 'networkidle0'});

await timeout(240000); // wait for the redirects to be finished

await page.waitForSelector(BTN_SLCT, {timeout: 240000}); // make sure the page is loaded <-- would fail here

await page.screenshot({path: './screenshots/mainpage.png'});

Answer

ilya picture ilya · Jul 12, 2019

I have encountered a similar issue and solved it by waiting for a specific selector in the desired page.

        await page.waitForSelector('#manage-trips', { visible: true, timeout: 0 });