Gerry
Gerry

Reputation: 1236

Puppetter Problems, waitForNavigation() returns immediately

I downloaded the latest version of Puppeteer a couple weeks ago, so I'm new with it. The first thing I noticed is that

await this.page.waitForNavigation();

does not seem to work. If I run in not headless mode and debug, I can see the waitForNavigation() returns as soon as navigation starts, not finishes. Who cares when navigation starts? You can't do anything until navigation is complete.

How can I be sure a page is ready? Right now I have had to fill my code with lots of

await this.page.waitFor(SomeDelayMs);

Upvotes: 0

Views: 226

Answers (1)

Taylor Krusen
Taylor Krusen

Reputation: 1033

Generally speaking, you're better off using:
await page.waitForSelector('your_selector')
That will cause puppeteer to wait until a specific selector is available before continuing execution. You can also use something like this if you're dealing with something that only shows up once clicked:
await page.waitForSelector('your_selector', {visible: True})

Upvotes: 2

Related Questions