Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would puppeteer wait for all redirects

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'});
like image 478
Roman Avatar asked Jul 30 '18 19:07

Roman


1 Answers

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 });
like image 141
ilya Avatar answered Oct 07 '22 09:10

ilya