{"schemaVersion":"1.0","canonicalUrl":"https://automationtester.in/failures/playwright-strict-mode-violation","slug":"playwright-strict-mode-violation","title":"Playwright strict mode violation","signature":"Error: strict mode violation: locator('button') resolved to 2 elements","frameworks":["Playwright"],"classification":"selector-drift","summary":"A Playwright locator expected to identify one element matched more than one, so Playwright refused an ambiguous action.","causes":[{"title":"The accessible name is duplicated","explanation":"Two controls now share the role and name used by the locator.","diagnostic":"Inspect every match and confirm whether the product created a duplicate control.","fix":"Add a unique accessible name or stable test id at the product boundary."},{"title":"A broad CSS or text selector is being used","explanation":"The selector describes appearance or copy rather than the intended control contract.","diagnostic":"Compare the current selector with getByRole, getByLabel, and getByTestId candidates.","fix":"Use the narrowest user-facing locator that remains unique."},{"title":"A hidden duplicate remains in the DOM","explanation":"Responsive or transitional UI may render two copies while only one is visible.","diagnostic":"Check visibility and responsive containers for every match.","fix":"Remove the duplicate from the DOM when inactive or scope the locator to the active region."}],"prevention":["Verify locator uniqueness in component tests.","Prefer role and accessible name contracts.","Avoid positional `.first()` as a repair."],"related":["playwright-timeout-exceeded","element-not-visible-or-actionable"],"references":[{"label":"Playwright locators","url":"https://playwright.dev/docs/locators"}]}