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.

Generalize page.waitFor, make waitForSelector a utility on top of it.

See original GitHub issue

Rationale: waitForSelector is rarely useful on its own. I have a DOM element, but it is off screen / display:none, etc.

We can make waitFor generic and execute it either upon every task (by default) or upon tasks that had specific activities in them (optional).


utilitites.waitForSelector = (selector) => {
  return page.waitFor(() => document.querySelector(selector), ['style'], selector);
}

utilitites.waitForLayout = () => {
  return page.waitFor(() => true, ['layout']);
}

utilitites.waitForFrame = () => {
  return page.waitFor(() => true, ['frame']);
}

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
aslushnikovcommented, Jul 19, 2017

We’ve spent some time discussing this and here’s what we’ve agreed upon so far:

await page.waitFor(1000); // to wait for 1000ms
await page.waitFor('body div'); // to wait for the 'body div' selector in body
await page.waitFor(() => Math.random() < 0.5); // to wait for the predicate

await page.waitForSelector('body div'); // the same as page.waitFor('body div')
// wait for the 'body div' to be present and visible in the page:
await page.waitForVisible('body div');
4reactions
JakubMatykacommented, Jun 5, 2018

I stuck on scenario when modal occurs and a button should be clicked. page.waitForSelector with flag visible: true does not work in this situation. The only way is to set timeout but I hate those

Read more comments on GitHub >

github_iconTop Results From Across the Web

Page.waitForSelector() method
Wait for the selector to appear in page. If at the moment of calling the method the selector already exists, the method will...
Read more >
puppeteer: how to wait until an element is visible?
I think you can use page.waitForSelector(selector[, options]) function for that purpose. const puppeteer = require('puppeteer'); ...
Read more >
puppeteer.Page.waitForSelector JavaScript and Node.js ...
Best JavaScript code snippets using puppeteer.Page.waitForSelector(Showing top 15 results out of 315) ; "[name='username']" ; }); await page.keyboard.press(' ...
Read more >
React Testing Library
The React Testing Library is a very light-weight solution for testing React components. It provides light utility functions on top of react-dom ...
Read more >
Getting to Know Puppeteer Using Practical Examples
Makes the browser to be launched in a headful way ... Option 2 - if we have a page instance, just using `waitFor`....
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