[Feature] Nicer API to wait for multiple elements
See original GitHub issueWhen 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:
- Created 3 years ago
- Reactions:3
- Comments:12 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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!
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 awaitForSelector
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: