-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[BUG] Looping all elements results in some elements being selected multiple times #22517
Comments
@hex0cter This is expected. |
@dgozman Thanks for the explanation. However my perception is that the problem is in test("should select all checkboxes by nth", async ({ page }) => {
const numberOfCheckboxes = await page.locator("rect[data-test='checkbox']").count();
for (let i = 0; i < numberOfCheckboxes; i++) {
await page.locator("rect[data-test='checkbox']").nth(i).click();
}
await expect(page.locator("[data-test='signview_sign_btn']")).toBeEnabled();
}); The result of this test is exactly the same as in the previous one, which indicate Many thanks. |
Yes, |
That makes sense. I will use other methods to go through the list then. Again thanks for your explanation! |
System info
Source code
Link to the GitHub repository with the repro
playwright-locator-loop
or
Config file
Test file (self-contained)
Steps
Expected
All checkboxes should be checked by the end of the tests. And the Next button on the bottom should be enabled
Actual
Some of the checkboxes are clicked multiple times and others are never clicked. When I looked at the trace, it seems when playwright loops through all the matching elements, it calls
locator.click(rect[data-test='checkbox'] >> nth=<n>
every time, and the order of that matched list may be non deterministic.The text was updated successfully, but these errors were encountered: