Selenium + Python · Lesson 19 of 43
Module 19: Alerts & Popups
Your task
Implement accept_alert_get_message(driver):
Write it in the editor, then press Check answer (Ctrl + Enter).
alert = driver.switch_to.alert
print("Alert message:", alert.text)
# Accept (OK):
alert.accept()
# Dismiss (Cancel):
# alert.dismiss()JavaScript alert dialogs freeze browser execution until confirmed or canceled. In this lesson, you will master driver.switch_to.alert, reading alert text, accepting confirms, and typing into prompt dialogs. Let's handle alerts!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
Selenium raises NoAlertPresentException. Always use WebDriverWait with EC.alert_is_present() first.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___