https://github.com/hex0cter/playwright-locator-loop
https://github.com/hex0cter/playwright-locator-loop
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hex0cter/playwright-locator-loop
- Owner: hex0cter
- Created: 2023-04-20T07:36:02.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T07:52:13.000Z (about 3 years ago)
- Last Synced: 2025-08-13T11:55:12.939Z (10 months ago)
- Language: HTML
- Homepage: https://github.com/microsoft/playwright/issues/22517
- Size: 1.09 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Looping all elements results in some elements being selected multiple times
### System info
- Playwright Version: 1.32.3
- Operating System: [macOS 13.2.1 (22D68)]
- Browser: [Chromium]
- Other info:
### Source code
- [x] I provided exact source code that allows reproducing the issue locally.
**Link to the GitHub repository with the repro**
[playwright-locator-loop](https://github.com/hex0cter/playwright-locator-loop)
or
**Config file**
```js
// playwright.config.ts
import { PlaywrightTestConfig } from "@playwright/test";
const config: PlaywrightTestConfig = {
timeout: 60 * 1000,
retries: 0,
snapshotDir: "./snapshots",
reporter: [
["html", { outputFolder: `playwright-report` }],
["line"],
],
projects: [
{
name: "chrome",
use: {
browserName: "chromium",
channel: "chrome",
headless: true,
viewport: { width: 1500, height: 730 },
acceptDownloads: true,
screenshot: "only-on-failure",
video: "on",
trace: "on",
},
}
],
};
export default config;
```
**Test file (self-contained)**
```js
test("should select all checkboxes by a loop", async ({ page }) => {
page.goto(
"https://staging.scrive.com/s/9221714692413010618/9221932570717574475/d0661b5e62380af4"
);
await page.waitForLoadState();
await page.waitForLoadState("networkidle");
const checkboxes = await page.locator("rect[data-test='checkbox']").all();
for (const checkbox of checkboxes) {
await checkbox.click();
}
await expect(page.locator("[data-test='signview_sign_btn']")).toBeEnabled();
});
```
**Steps**
- npm install
- npm test
**Expected**
All checkbox should be checked by the end of the tests. And the Next button on the bottom should be enabled
**Actual**
Some of the checkbox 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=` every time, and the order of that matched list may be non deterministic.