Skip to content

[Feature]: Automatic waiting to resolve strict mode violations #36045

Closed as not planned

Description

🚀 Feature Request

When there is a strict mode violation, instead of immediately raising an exception, wait the usual time for the strict mode violation to resolve

Example

In a test scenario, where an open dialog should be closed by clicking the close button:

await page.getByLabel('close').click();

If there are still some auto-disappearing toast messages visible on the page, and they have a dismiss-button with the same label, the test will immediately crash.

Current workaround:

await expect(page.getByLabel('close')).toHaveCount(1);
await page.getByLabel('close').click();

Suggested change:

Instead, each action that would raise a strict-mode-violation should first perform an expect wait like from the workaround, and only actually fail when the violation is still present after the timeout.

Motivation

It would make workarounds like above unnecessary, and also align the code generated from the recording feature more aligned with the actual working test code.

Activity

  1. dacloutier-logmein commented on May 30, 2025

    @dacloutier-logmein

    I like the idea, also had to cope with similar problems.

  2. toduyemi commented on Nov 17, 2025

    @toduyemi

    Please this really should be a high priority. Playwright touts its auto-waiting and retry-ability especially when it comes to Locators. This behaviour has been documented (#30363) to be throwing false negatives for a while now.

    Currently I have multiple flaky test scenarios where I navigate to a new page, then click on a button. Playwright throws a strict mode violation while the new page has barely started loading, due to the previous page having elements that match the button Locator. I've currently worked around around with load state waits, but even that's still inconsistent, i might have to turn to hard waits.

    This behaviour of throwing an error and failing the test before the browser has even registered the previous action violates the philosophy of Locators and their in-built auto-wait and auto-retry mechanism. This is the exact sort of flakey behaviour that playwright locators are designed to avoid. Why are strict-mode errors a fail-fast exception to this?

  3. MiladSadinam commented on Nov 27, 2025

    @MiladSadinam

    I would also highly appreciate this, as we regularly have flaky strict mode violations because there is no auto-waiting on that check.

    It is just practically not feasible to add everywhere .toHaveCount(1) when the framework could take over this job.

  4. toduyemi commented on Jan 29, 2026

    @toduyemi

    Is there any update or discussion to this? This issue stays cropping up.

  5. rstarkov commented on Mar 3, 2026

    @rstarkov

    It really is an odd choice. Waiting for success is one of the genius ideas that Playwright great. But the reality is this: zero matches = wait, two matches = insta-fail. Just why?

    Use case: React 19 has forced me to use startTransition on navigations, which means that click is not immediately followed by the current page disappearing. Every single test that happens to match two things on the old screen is now broken, and we have a lot of tests that match on simple selectors like "button titled Edit".

  6. markustauscher commented on Apr 20, 2026

    @markustauscher

    I seem to be having a similar issue in vaadin ui with a select drop down. I still don't know why, but i'm randomly getting strict mode violation because it finds the same item in a select drop down twice. When the run fails, it usually fails on a different value available in the select drop down.

    We can't get it to fail running it during the day so for sure a few milliseconds of waiting time to see if the violation disappears by itself wouldn't be a huge issue.

  7. pavelfeldman commented on Oct 31, 2026

    @pavelfeldman
    Member

    We're closing all P3-collecting-feedback issues and retiring the label. #43813 explains why. This doesn't mean the request is wrong. If it still matters to you, please open a new issue against the latest Playwright version with your concrete use case and link back here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions