puppeteer: Navigation after click not working regardless of actions I take

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.11
  • Platform / OS version: WSL (openSUSE on Windows)
  • URLs (if applicable): -
  • Node.js version: 10

What steps will reproduce the problem?

So in pure text what I am trying:

  1. Click a button.
  2. Wait until navigation loads. Or simply put - link changes.
  3. Fetch url.
  4. In different incognito browser go to the link and do other actions.

Unfortunately, because I need to fetch the link I can’t use waitForSelector. So I am stuck with navigation and the headache all of that causes. Url is a casual link with dynamically generated ID that I can’t access otherwise.

Code:

await helpers.click(mainUserPage, '#RematchButton');
await mainUserPage.waitForNavigation({waitUntil: "networkidle0"});
 let gameUri = mainUserPage.url();
    await weakerUserPage.goto(gameUri, {
        waitUntil: ['load']
    });

helpers.click:

async function click(page, button) {
   try {
     await page.waitForSelector(button, {visible: true});
     await page.click(button);
   } catch (e) {
     console.log(e);
   }
 }

I tried Promise.all([]) - didn’t help at all. So really I don’t know what to do with that. I am sure navigation causes the headache as without the line button is clicked and navigation is done, just wrong url is fetched.

What is the expected result? Navigation

What happens instead? Blockage

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Alright another update. After changing navigation lines to:

 async function nativeClick(page, button) {
   await page.evaluate((button) => {
     document.querySelector(button).click();
   }, button);
 }

and using it instead of built-in click method surprisingly the code works 100% and never stops at navigation. Otherwise when there’s a conflict between click redirect & navigation there are ALWAYS problems.

Overall puppeteer is a great library but page.click is one huge headache. Even the method itself sometimes works, sometimes it doesn’t… really weird thing.