Closed
Description
openedon 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels