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.

[Feature] Nicer API to wait for multiple elements

See original GitHub issue

When I want to get some content in a span in a <td> element, I have to do the below. I was just wondering if there is a nicer API for this, or if not, there should be?

It is quite common to want to get multiple elements like this, but only after the selector is visible (or even better possibly using the Auto-waiting functionality.

await page.waitForSelector('#users-table tr td span');
const text = await page.$$eval('#users-table tr td span', (spans) =>
  spans.map((span) => span.textContent)
);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
aslushnikovcommented, May 14, 2020

We find this used in about 30% of our test cases where we look for lists of things (tables, grids/flexbox items etc.).

@thernstig Let’s live for some more time and see. Hopefully more use-cases will emerge, and we might be able to come up with a good API!

1reaction
thernstigcommented, Apr 30, 2020

My reasoning is that the only way to get multiple elements is with page.$$ as of now. Now all the $ functions has no wait functionality, they just execute immediately. This means I anyway have to have a waitForSelector in this cases to wait for some kind of element to exist in the DOM (or to be visible).

I believe I was after a one-liner that combines them. But you are much more adapt at all things DOM. So maybe there is a better idea? Or it is possible the current way of doing this (like in my original post) is the best way and should not change?

I’ve just felt it looks a bit “ugly” and it could be nicer, but I am also not entirely sure. I am reasoning that the above must be common enough to do in tables, lists etc. of sorts.

Note that lately I’ve been doing this instead:

await page.waitForSelector('#users-table tr td span');
const spans = await page.$$eval('#users-table tr td span');
const text = spans.map((span) => span.textContent());
Read more comments on GitHub >

github_iconTop Results From Across the Web

Waiting for multiple all API responses to complete with the ...
On some pages, we needed to wait for multiple API requests to complete before rendering content. Today, I want to show you a...
Read more >
webdriver wait for one of a multiple elements to appear
It involves waiting an entire 10 seconds before it looks to see if the message that the file already exists on the system....
Read more >
Dequeue with wait on multiple queues similar ... - NI Community
Current Scenario: for dequeue element we can pass one reference only. And the function waits till timeout if no element is present in...
Read more >
Selenium Wait Tutorial with All Strategies!
All Selenium Wait Strategies are explained, you can find examples for implicit wait, explicit wait, fluent wait and wait for page to load....
Read more >
Intersection Observer API - MDN Web Docs
Whether you're using the viewport or some other element as the root, the API works the same way, executing a callback function you...
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