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.

waitForSelector not working as intended?

See original GitHub issue

Steps to reproduce

This is tested on a React App.

  await page.click(sel('sign-in'))
 // ↑ screen transition
  await page.waitForSelector(sel('main-dashboard'), { timeout: 1000 })
 // **without timeout: 1000 it crashes** I can use that or `page.waitFor(1000)`
  await page.waitForSelector(sel('btn-projects'))
  await page.click(sel('btn-projects'))
  await page.waitForSelector(sel('btn-create-project'))
 // ↑ opens modal
  await page.click(sel('btn-create-project'))
  await page.waitForSelector(sel('input-project-name'))
  await page.type(sel('input-project-name'), 'test-project')
  await page.waitForSelector(sel('btn-project-submit'))
  await page.click(sel('btn-project-submit'))
 // ↑ makes a request and closes modal
  await page.waitForSelector(sel('test-project'), { timeout: 1000 })
// ↑ **does not work. I have to use await page.waitFor(250)** the created item would show up on the dashboard
  await page.click(sel('test-project'))

I’m not sure if this is a bug or not but I think it relates to #2192

Why does await page.waitForSelector(sel('main-dashboard'), { timeout: 1000 }) work when await page.waitForSelector(sel('test-project'), { timeout: 1000 }) does not. Response from the server can take time, which is why I added the timeout: 1000. With await page.waitForSelector(sel('test-project'), { timeout: 1000 }) it does not matter how much time I give it, it wouldn’t work unless I use page.waitFor(250) The page.waitForNavigation method doesn’t work on it either.

Sometimes requests take longer, and I will have to increase the time interval to page.waitFor Right now, whenever a await page.waitForSelector does not work, I add page.waitFor(250) right about it to quick patch it. If 250 crashes, I add 500, or 1000 and so forth, which seems kinda hacky. Is there a better way of handling it?

Expected Result

After await page.click(sel('btn-project-submit')), the tests should continue to run

Actual Result

After await page.click(sel('btn-project-submit')), it does show the POST request in the server log and then hangs. Puppeteer with Jest then just returns the typical Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

Tell us about your environment:

  • Puppeteer version: 1.4
  • Platform / OS version: Mac
  • Node.js version: 8.10

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
chantlongcommented, May 31, 2018

@aslushnikov Let me get back to you on that matter.

2reactions
chantlongcommented, May 31, 2018

@aslushnikov Thanks but can you please clarify on…

With await page.waitForSelector(sel(‘test-project’), { timeout: 1000 }) it does not matter how much time I give it, it wouldn’t work unless I use page.waitFor(250) The page.waitForNavigation method doesn’t work on it either.

Sometimes requests take longer, and I will have to increase the time interval to page.waitFor Right now, whenever a await page.waitForSelector does not work, I add page.waitFor(250) right about it to quick patch it. If 250 crashes, I add 500, or 1000 and so forth, which seems kinda hacky. Is there a better way of handling it?

The timeout: 5000 doesn’t solve the problem. page.waitFor(250) solves the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Puppeteer waitForSelector not working as expected
waitForSelector () ? This seems working: import puppeteer from 'puppeteer'; const browser = await puppeteer.launch({ headless: false, ...
Read more >
Puppeteer waitForSelector not working as expected-node.js
Coding example for the question Puppeteer waitForSelector not working as expected-node.js.
Read more >
Frame.waitForSelector() method - Puppeteer
Frame.waitForSelector() method. Waits for an element matching the given selector to appear in the frame. This method works across navigations.
Read more >
ElementHandle | Playwright - CukeTest
note. This method does not work across navigations, use page.waitForSelector(selector[, options]) instead.
Read more >
puppeteer waitforselector - Unisa
waitFor (linkEx), waitForSelector(linkEx) but it's not working. ... That said, if it's not meant to work that way then I'd be interested to...
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