[Python] How to make playwright wait for two elements in the same time and continue after it...

Discussão em 'Python' iniciado por Stack, Julho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using playwright with python. I'm looking to wait for 2 elements. e.g. locator1 and locator2. After playwright sees one of these elements it will return the one it found first then finish the function. In selenium I used an expected condition called "any_of" but I could not find an equivilant in playwright.

    I do not want something like:

    def wait_for_any_visible(page, locator1, locator2, timeout=10000):
    try:
    return page.locator(locator1).wait_for(state="visible", timeout=timeout)
    except TimeoutError:
    return page.locator(locator2).wait_for(state="visible", timeout=timeout)


    Because it will just vastly increase the duration of script

    Continue reading...

Compartilhe esta Página