Search code examples
pythonselenium-webdriverplaywrightplaywright-python

How to wait for element not present using Playwright


I need to translate Selenium code into Playwright.

code:

self.wait_for_element_not_present("element CSS here")

Is the solution:

Not self.page.locator("element CSS here").is_visible()

Solution

  • You can use the not_be_visible expect assertion for this.

    expect('element CSS here').not_to_be_visible()
    

    By default expect assertions have a 5 second timeout, in case you want to increase the timeout, you can do like this:

    expect('element CSS here').not_to_be_visible(timeout=7000)