Playwright Error: strict mode violation: locator resolved to 2 elements

Locator matched multiple DOM nodes; Playwright refuses to guess which one to click.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: Playwright Error Platform: JavaScript
Common Root Causes:
  • Locator matched multiple DOM nodes; Playwright refuses to guess which one to click.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Narrow locator using `getByRole("button", { name: "Exact", exact: true })` or parent scoping.
Safe Diagnostic Command:
Run with `PWDEBUG=1` or inspect locator count
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Locator matched multiple DOM nodes; Playwright refuses to guess which one to click. Recommended diagnostic: `Run with `PWDEBUG=1` or inspect locator count`. Remediation: Narrow locator using `getByRole("button", { name: "Exact", exact: true })` or parent scoping.

Worked Examples

  • Run `Run with `PWDEBUG=1` or inspect locator count` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-playwright-strict-mode-violation · Independently verified: 2026-11-25

Related Resources