Skip to content

Commit 3ead74b

Browse files
Use EC.alert_is_present() for Python alert examples
Replace implicit lambda workaround with purpose-built expected condition for alert handling in all three Python alert examples. Fixes #2548
1 parent 77549cd commit 3ead74b

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

examples/python/tests/interactions/test_alerts.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from selenium import webdriver
22
from selenium.webdriver.common.by import By
33
from selenium.webdriver.support.ui import WebDriverWait
4+
from selenium.webdriver.support import expected_conditions as EC
45

56
global url
67
url = "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

2324
def 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

Comments
 (0)