question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The page.waitForNavigation({waituntil:'networkidle2'}) would be waiting until time out if network has already been idled before invoke it.

See original GitHub issue

For examle: await page.goto("https://www.aqistudy.cn/html/city_realtime.html?v=2.3", { waitUntil: "networkidle2" }); await page.type("#city", cities[i]); await page.tap("a#btnSearch"); await page.waitForNavigation({ waitUntil: "networkidle2" }); After the #btnSearch is tapped, the web uses javascript to access data to render the table. I thought using waitForNavigation could get the right result. However, the page would always be waiting until time out. It doesn’t work as I expected. How could I fix it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
vonGameTheorycommented, Nov 27, 2017

Not sure about your specific code and whether your click is “happening” on the right element to trigger navigation, but in general if you want to make sure you catch an expected navigation event, create the waitForNavigation promise (but do not await it yet) BEFORE you trigger the navigation, i.e. before the click, not after. And then “await” that created promise, otherwise sometimes it will have happened so fast you will miss it.

So something like:

navresponse = page.waitForNavigation(['networkidle0', 'load', 'domcontentloaded']);
page.click('a#btnSearch');
await navresponse;  
1reaction
vc1commented, Nov 30, 2017

调接口抓数据吧


var method = 'GETDATA';
var object = {};

function getServerData(method, object, callback, period) {
  const key = hex_md5(method + JSON.stringify(object));
  const data = getDataFromLocalStorage(key, period);
  if (!data) {
    var param = getParam(method, object);
    $.ajax({
      url: '../apinew/aqistudyapi.php',
      data: {
        d: param
      },
      type: "post",
      success: function(data) {
        data = decodeData(data);
        obj = JSON.parse(data);
        if (obj.success) {
          if (period > 0) {
            obj.result.time = new Date().getTime();
            localStorageUtil.save(key, obj.result)
          }
          callback(obj.result)
        } else {
          console.log(obj.errcode, obj.errmsg)
        }
      }
    })
  } else {
    callback(data)
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get Puppeteer waitForNavigation Working after click
The function page.waitForNavigation() waits for navigation to begin and end. The navigation has already been initiated with page.click() .
Read more >
Page.waitForNetworkIdle() method - Puppeteer
class Page { waitForNetworkIdle(options?: { idleTime?: number; timeout?: number; } ... Promise which resolves when network is idle. Previous. Page.
Read more >
Navigation and loading | Playwright 中文文档
Page navigation can be either initiated by the Playwright call: ... Page load takes time retrieving the response body over the network, parsing, ......
Read more >
5 - Auto-Waiting mechanism in Playwright with C# .NET
In this video, we will discuss the working Auto- Waiting mechanism of Playwright with C# .NET and how the actionability and retry-ability ...
Read more >
How to make puppeteer wait for page to load - Urlbox
Taking a screenshot before the page has fully loaded will result in a bad screenshot where images are not loaded and styles have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found