seleniumhq.github.io
seleniumhq.github.io copied to clipboard
JavaScript alerts, prompts and confirmations - Non-working (?) example in python
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 :
- Does not really correspond to the semantic of
wait.until - Does not work if the alert is generated on the return of an
asyncfunction
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 ...
noticed in other programming language examples expected conditions is alert present is used, but observation about python seems correct. if you would like to contribute and improve the example in documentation, please do.