There are multiple ways to switch to alert pop-up in Python
:
alert = driver.switch_to_alert()
switch_to
:alert = driver.switch_to.alert
ExplicitWait
: from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
alert = WebDriverWait(driver, TIMEOUT_IN_SECONDS).until(EC.alert_is_present())
Alert
class:from selenium.webdriver.common.alert import Alert
alert = Alert(driver)
To fill input field in pop-up triggered by JavaScript
prompt()
:
alert.send_keys('Some text to send')
To confirm dialog pop-up*:
alert.accept()
To dismiss:
alert.dismiss()
To get text from pop-up:
alert.text
*P.S. alert.dismiss()
could be used to confirm pop-ups triggered by JavaScript
alert()
as well as alert.confirm()