-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Locator.all: get list of Locator#nth(index) for each index #11909
Comments
For scraping, you would more likely to do something like: page.locator('.result-item').evaluateAll(ee => ee.forEach(e => ...)) No need to go back and forth between the browser and playwright... |
It is right. In most cases,
I know |
Note that However, you can work with lists instead of wrapping each locator individually if you'd like: class LikeItemSections {
constructor(likeItemRoots) {
this.avatars = likeItemRoots.locator('img')
this.displayNames = likeItemRoots.locator('span.name')
}
}
// ...
this.likes = new LikeItemSections(itemRoot.locator('liked_container .like')) At any moment, you can use a "list" locator to retrieve data or verify something with |
Closing because Two suggested workarounds:
|
Implemented in Playwright 1.29! Thank you! |
#11865 (comment) shows a good example of how to use locator just like
page.$$
I often use this approarch for scraping some search results, our company's daily reports, and so on.
It would be cool if we can write the logic for collecting nth(index) of locator like
const itemLocators = page.locator('.result-item').all()
I used Page.$$ before Locator is introduced, howevert ElementHandle is now discouraged. I want a method alternatives to Page.$$ for Locator.
The text was updated successfully, but these errors were encountered: