11from selenium import webdriver
22from selenium .webdriver .common .by import By
33from selenium .webdriver .support .ui import WebDriverWait
4+ from selenium .webdriver .support import expected_conditions as EC
45
56global url
67url = "https://www.selenium.dev/documentation/webdriver/interactions/alerts/"
@@ -13,11 +14,11 @@ def test_alert_popup():
1314 element .click ()
1415
1516 wait = WebDriverWait (driver , timeout = 2 )
16- alert = wait .until (lambda d : d . switch_to . alert )
17+ alert = wait .until (EC . alert_is_present () )
1718 text = alert .text
1819 alert .accept ()
1920 assert text == "Sample alert"
20-
21+
2122 driver .quit ()
2223
2324def test_confirm_popup ():
@@ -27,7 +28,7 @@ def test_confirm_popup():
2728 driver .execute_script ("arguments[0].click();" , element )
2829
2930 wait = WebDriverWait (driver , timeout = 2 )
30- alert = wait .until (lambda d : d . switch_to . alert )
31+ alert = wait .until (EC . alert_is_present () )
3132 text = alert .text
3233 alert .dismiss ()
3334 assert text == "Are you sure?"
@@ -41,7 +42,7 @@ def test_prompt_popup():
4142 driver .execute_script ("arguments[0].click();" , element )
4243
4344 wait = WebDriverWait (driver , timeout = 2 )
44- alert = wait .until (lambda d : d . switch_to . alert )
45+ alert = wait .until (EC . alert_is_present () )
4546 alert .send_keys ("Selenium" )
4647 text = alert .text
4748 alert .accept ()
0 commit comments