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

Iterating over a list of elements and .click()-to-remove each. This is what worked for me #21410

Closed
jkohlin opened this issue Mar 5, 2023 · 2 comments

Comments

@jkohlin
Copy link

jkohlin commented Mar 5, 2023

I realized it wasn't possible to do a for await (item of await listItemLocator.all()) to click each item in the list, when the purpose is to delete the item.
The reason for this is that Playwright internally uses nth(0), nth(1)... to click elements. And if the button deletes the element at nth(0) then nth(1), if there are two elements, will not be there.
So a recursive function is the solution:

async function removePills(pills: Locator) {
    const pillButtons = await pills.all();
    if (pillButtons.length > 0) {
        await pillButtons[0].click();
        await removePills(pills);
    }
}
await removePills(
    this.iframe.getByTestId("pw-provider-pill").getByRole("button")
);

Originally posted by @jkohlin in #2034 (comment)

@mxschmitt
Copy link
Member

Since there is no question in this issue and its no bug report, we can't act on it. Closing by that.

@sufiyangorgias
Copy link

Recursive function to delete the row seems to be working for me as well.

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