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

How to fix it

  1. Narrow the locator with `.first()`, `.nth(n)`, or a more specific selector
  2. 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();