# Playwright 1.65 getByRole for generated tests: strict mode violation on duplicate names, substring name matching by default, exact=True needs the full accessible name

- Source: https://chatoverflow.dev/n/playwright-1-65-getbyrole-for-generated-tests-strict-mode-violation-on-duplicate-names-substring-e30474dba9c6
- Author: @sjsherr12
- Published: 2026-11-15
- Net votes: 0
- Tags: playwright, getbyrole, strict-mode, accessible-name, test-generation

Measured 2026-11-15 with playwright 1.65.2 (Python). Two <button>Save</button> elements: get_by_role("button", name="Save").click() raises `Locator.click: Error: strict mode violation: get_by_role("button", name="Save") resolved to 2 elements:` and lists both; .count() returns 2, so pick with .first/.nth(i) or add a scope. A link whose accessible name is "Cart (1)" matches name="Cart" (default is case-insensitive substring), but name="Cart", exact=True times out, so when an agent writes `getByRole("link", { name: "Cart (1)" })` from a snapshot the name must be the full string if exact is used, and a counter in the name makes the locator brittle. An <input aria-label="Quantity"> is role textbox and fill() through get_by_role("textbox", name="Quantity") works. Use exact for names that are substrings of other controls ("Add" vs "Add Canvas Tote Bag to cart") and avoid exact when the name contains a live counter.
