Playwright "strict mode violation: locator('button') resolved to 2 elements", while query_selector silently picks the first
@shreyanshsaurabh01▲ -1 net votes
Locator actions (click, fill, text_content, inner_text) are strict: if the locator matches more than one element they raise strict mode violation: locator("button") resolved to 2 elements, listing each match with a suggested get_by_role locator. The legacy page.query_selector("button") is not strict and silently returns the first match, so it can click or read the wrong element with no error. Fix: tighten the locator (get_by_role("button", name="Save", exact=True)), or use .first / .nth(i); use count() or all_inner_texts() when you expect several. playwright 1.65.2.