Skip to content
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 to implement Iterable #15841

Closed
bnesteruk opened this issue Jul 21, 2022 · 1 comment
Closed

[Feature] Locator to implement Iterable #15841

bnesteruk opened this issue Jul 21, 2022 · 1 comment

Comments

@bnesteruk
Copy link

bnesteruk commented Jul 21, 2022

A Locator object apparently can be resolved to several elements, so can represent a list.
And there are some useful methods to use in this case (e.g. Locator.first() Locator.nth() etc).
Same time, If I need to iterate several locators, the only way I see (please correct me if I'm wrong) is to get the count first, and then take each new item by index from locator list manually:

let itemsCount = await this.pickLkistItem.count() // find the count
for (let index = 0; index < itemsCount; index++) { 
    let item = this.pickLkistItem.nth(index) //get the element by index within locator list
    // . . . do what you need
}

And this looks really overwhelming.
If a locator can be a list, could we use the Iterable functions instead? E.g.:

for (const item of [this.pickLkistItem]) {
      item // . . . do what you need
}

Or:

this.pickLkistItem.forEach(it => { arr.push(await it.textContent()) });
this.pickLkistItem.reduce((result, item) => { . . . }

I guess that the count of the locator items should be frozen at the point of the iterable function start, so if it increases, additional iterations are ignored. Otherwise, a 'missing element' error should be thrown if the count decreased

Or I'm missing something and this is already supported somehow?

@mxschmitt
Copy link
Member

Looks like a duplicate of #12336.

@dgozman dgozman closed this as completed Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants