Skip to content

JavaScript alerts, prompts and confirmations - Non-working (?) example in python #2548

@kjo-sdds

Description

@kjo-sdds

It seems that the example in Python (can't speak for the other languages, I'm only using python) is not the best suited :

    wait = WebDriverWait(driver, timeout=2)
    alert = wait.until(lambda d : d.switch_to.alert)
    text = alert.text
    alert.accept()

Seems to ONLY work if the alert is already present at the time the code runs. Which :

  1. Does not really correspond to the semantic of wait.until
  2. Does not work if the alert is generated on the return of an async function

Especially it seems there's a way made specifically for that :

from selenium.webdriver.support import expected_conditions as EC

# [...]

        wait = WebDriverWait(driver, timeout=4)
        alert = wait.until(EC.alert_is_present())
        text = alert.text
        alert.accept()

Maybe I missed it (then it's just me the moron) ... but kind of a bummer that I had to find it elsewhere than the docs ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions