Playwright error Error: strict mode violation: locator resolved to 2 elements
Playwright's strict mode refuses to act on a locator that matches more than one element instead of silently picking the first.
Why this happens
- The selector is too broad and matches multiple elements on the page (e.g. repeated list rows or duplicate buttons)
How to fix it
- Narrow the locator with `.first()`, `.nth(n)`, or a more specific selector
- Prefer `page.getByRole()` with an accessible name over a generic CSS selector, since it's usually unique by construction
Example
await page.getByRole('button', { name: 'Submit' }).first().click();