{"title":"Triage a Playwright Strict Mode Error Before Editing the Locator","excerpt":"A Playwright strict mode error means a locator matched multiple elements. Inspect the matches before changing the test.","canonicalUrl":"https://automationtester.in/blog/tools-reviews/triage-playwright-strict-mode-before-editing-locator","category":{"name":"Tools & Reviews","slug":"tools-reviews"},"tags":["playwright","failure-triage","locators"],"author":{"name":"Shashank Rawlani","url":"https://shashank.rawlani.com","linkedin":"https://www.linkedin.com/in/shashankrawlani/"},"datePublished":"2026-10-18T05:30:00.000Z","dateModified":"2026-10-14T10:26:49.919Z","coverImage":{"url":"https://ik.imagekit.io/automationtester/automationtester-in/blog/covers/v3/triage-playwright-strict-mode-before-editing-locator.webp","alt":"An orange failure-log panel enters a dashed local triage gate. Two green branches leave the central node toward separate button panels, inviting inspection of both matches."},"contentHtml":"<p>A Playwright strict mode error says an action had more than one target. Paste the causal line into <a href=\"https://automationtester.in/tools/test-failure-triage\">Test Failure Triage</a> for a likely failure pattern and diagnostic checks, then inspect the actual matches before editing the locator.</p>\n<h2 id=\"feed-it-the-first-causal-line\">Feed it the first causal line</h2>\n<p>Paste this reduced error into the “Failure evidence” field:</p>\n<pre><code>Error: strict mode violation: locator(\"button\") resolved to 2 elements</code></pre>\n<a href=\"https://automationtester.in/tools/test-failure-triage#p=eyJ2IjoxLCJpbnB1dCI6IkVycm9yOiBzdHJpY3QgbW9kZSB2aW9sYXRpb246IGxvY2F0b3IoXCJidXR0b25cIikgcmVzb2x2ZWQgdG8gMiBlbGVtZW50cyJ9\">Try this in Test Failure Triage</a>\n<p>The live page classifies it as <strong>Selector drift</strong>, with <strong>high confidence</strong>. It says a locator expected one element but matched more than one. Its first repair suggestion is to add a unique accessible name or stable test ID at the product boundary. The diagnostic list asks you to inspect every match, compare role, label, and test-ID candidates, then check visibility and responsive containers. It links to the full strict mode violation guide.</p>\n<p>That result is a hypothesis grounded in a known error signature. It is not proof that the UI regressed. Two “Save” buttons might be legitimate: one in a dialog and one in the page behind it. The right repair could be scoping the locator to the dialog, rather than renaming either button.</p>\n<h2 id=\"inspect-the-candidates-on-the-failing-page\">Inspect the candidates on the failing page</h2>\n<p>In Playwright, check the count and names before changing the action:</p>\n<pre><code>const saveButtons = page.getByRole('button', { name: 'Save' });\nconsole.log(await saveButtons.count());</code></pre>\n<p>Then inspect the trace from the failing run. A count of two in a pasted HTML sample can help, but the rendered page and trace show the actual responsive state. Playwright's strictness applies to actions that require a single target; a broad locator can be valid for counting and still be invalid for clicking.</p>\n<h2 id=\"the-rule-set-has-a-boundary\">The rule set has a boundary</h2>\n<p>The site runs deterministic matching rules in the browser. It does not upload this text for model analysis. A recognized signature gives a classification, confidence, and maintained guide; unfamiliar text returns “No deterministic match.” A high-confidence label means the rule matched strongly, not that the first suggested fix is certainly correct. Preserve the original trace and stack, and reduce sensitive data before sharing evidence elsewhere.</p>\n<p>The broader <a href=\"https://automationtester.in/blog/tools-reviews/failure-triage-toolkit-before-flake\">failure triage toolkit article</a> covers capture, retries, and CI artifacts. This page is for the first local classification. Use traces and the actual DOM to decide the repair.</p>\n<h2 id=\"sources\">Sources</h2>\n<ul>\n<li><a href=\"https://automationtester.in/tools/test-failure-triage\">AutomationTester.in Test Failure Triage</a></li>\n<li><a href=\"https://playwright.dev/docs/locators\">Playwright locators and strictness</a></li>\n</ul>\n"}