From 3ead74ba69359f6fca0db3669f0aed950c23188f Mon Sep 17 00:00:00 2001 From: beinghumantester Date: Sun, 22 Feb 2026 14:56:40 +0530 Subject: [PATCH 1/3] 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 --- examples/python/tests/interactions/test_alerts.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/python/tests/interactions/test_alerts.py b/examples/python/tests/interactions/test_alerts.py index 59b2cb15698c..067c21c41941 100644 --- a/examples/python/tests/interactions/test_alerts.py +++ b/examples/python/tests/interactions/test_alerts.py @@ -1,6 +1,7 @@ from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC global url url = "https://www.selenium.dev/documentation/webdriver/interactions/alerts/" @@ -13,11 +14,11 @@ def test_alert_popup(): element.click() wait = WebDriverWait(driver, timeout=2) - alert = wait.until(lambda d : d.switch_to.alert) + alert = wait.until(EC.alert_is_present()) text = alert.text alert.accept() assert text == "Sample alert" - + driver.quit() def test_confirm_popup(): @@ -27,7 +28,7 @@ def test_confirm_popup(): driver.execute_script("arguments[0].click();", element) wait = WebDriverWait(driver, timeout=2) - alert = wait.until(lambda d : d.switch_to.alert) + alert = wait.until(EC.alert_is_present()) text = alert.text alert.dismiss() assert text == "Are you sure?" @@ -41,7 +42,7 @@ def test_prompt_popup(): driver.execute_script("arguments[0].click();", element) wait = WebDriverWait(driver, timeout=2) - alert = wait.until(lambda d : d.switch_to.alert) + alert = wait.until(EC.alert_is_present()) alert.send_keys("Selenium") text = alert.text alert.accept() From 0202f981a8e2f138c6fe6c7b32ef8be6fe193039 Mon Sep 17 00:00:00 2001 From: beinghumantester Date: Sat, 13 Jun 2026 17:00:42 +0530 Subject: [PATCH 2/3] Update alert documentation code block references --- .../documentation/webdriver/interactions/alerts.en.md | 6 +++--- .../documentation/webdriver/interactions/alerts.ja.md | 6 +++--- .../documentation/webdriver/interactions/alerts.pt-br.md | 6 +++--- .../documentation/webdriver/interactions/alerts.zh-cn.md | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md index 432946b674af..252854279774 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md @@ -30,7 +30,7 @@ alerts. {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L18" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L20" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -81,7 +81,7 @@ This example also shows a different approach to storing an alert: {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L32" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L34" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -140,7 +140,7 @@ See a sample prompt. {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L47" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L49" >}} {{< /tab >}} {{< tab header="CSharp" >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md index 1e5d9716351f..ce13b7587a9b 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md @@ -26,7 +26,7 @@ WebDriverはポップアップからテキストを取得し、これらのア {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L18" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L20" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -76,7 +76,7 @@ alert.accept() {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L32" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L34" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -133,7 +133,7 @@ alert.dismiss() {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L47" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L49" >}} {{< /tab >}} {{< tab header="CSharp" >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md index aadb4a30575b..7d5d8167dd54 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md @@ -29,7 +29,7 @@ alertas. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/AlertsTest.java#L36-L41" >}} {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L18" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L20" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} @@ -67,7 +67,7 @@ Este exemplo também mostra uma abordagem diferente para armazenar um alerta: {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L32" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L34" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -126,7 +126,7 @@ Veja um exemplo de prompt . {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L47" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L49" >}} {{< /tab >}} {{< tab header="CSharp" >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md index a59b74bebf9c..03711b375431 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md @@ -23,7 +23,7 @@ WebDriver可以从弹窗获取文本并接受或关闭这些警告. {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L18" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L20" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -72,7 +72,7 @@ alert.accept() {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L32" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L34" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -128,7 +128,7 @@ alert.dismiss() {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L47" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L49" >}} {{< /tab >}} {{< tab header="CSharp" >}} From c5b7ae57fec7f13c40b93bea73da42cc89d6fa42 Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Sun, 19 Jul 2026 00:05:19 +0200 Subject: [PATCH 3/3] Remove trailing whitespace and fix codeblock line ranges Addresses cgoldberg's review comment about the trailing whitespace, and corrects the gh-codeblock line ranges in alerts.en.md, alerts.ja.md, alerts.pt-br.md, and alerts.zh-cn.md. The previous update widened each range by one extra line on both ends instead of shifting by the single line the new import adds, so the rendered Python snippets pulled in driver.get(url) and the assert line that the other language tabs intentionally omit. Co-Authored-By: Claude Sonnet 5 --- examples/python/tests/interactions/test_alerts.py | 2 +- .../documentation/webdriver/interactions/alerts.en.md | 6 +++--- .../documentation/webdriver/interactions/alerts.ja.md | 6 +++--- .../documentation/webdriver/interactions/alerts.pt-br.md | 6 +++--- .../documentation/webdriver/interactions/alerts.zh-cn.md | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/python/tests/interactions/test_alerts.py b/examples/python/tests/interactions/test_alerts.py index 067c21c41941..31fdafc7b572 100644 --- a/examples/python/tests/interactions/test_alerts.py +++ b/examples/python/tests/interactions/test_alerts.py @@ -18,7 +18,7 @@ def test_alert_popup(): text = alert.text alert.accept() assert text == "Sample alert" - + driver.quit() def test_confirm_popup(): diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md index 252854279774..2887b41d4a01 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.en.md @@ -30,7 +30,7 @@ alerts. {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L20" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L13-L19" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -81,7 +81,7 @@ This example also shows a different approach to storing an alert: {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L34" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L27-L33" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -140,7 +140,7 @@ See a sample prompt. {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L49" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L41-L48" >}} {{< /tab >}} {{< tab header="CSharp" >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md index ce13b7587a9b..ae6ed0779f6a 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md @@ -26,7 +26,7 @@ WebDriverはポップアップからテキストを取得し、これらのア {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L20" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L13-L19" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -76,7 +76,7 @@ alert.accept() {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L34" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L27-L33" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -133,7 +133,7 @@ alert.dismiss() {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L49" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L41-L48" >}} {{< /tab >}} {{< tab header="CSharp" >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md index 7d5d8167dd54..638b834ed540 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md @@ -29,7 +29,7 @@ alertas. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/interactions/AlertsTest.java#L36-L41" >}} {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L20" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L13-L19" >}} {{< /tab >}} {{< tab header="Ruby" text=true >}} @@ -67,7 +67,7 @@ Este exemplo também mostra uma abordagem diferente para armazenar um alerta: {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L34" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L27-L33" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -126,7 +126,7 @@ Veja um exemplo de prompt . {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L49" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L41-L48" >}} {{< /tab >}} {{< tab header="CSharp" >}} diff --git a/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md b/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md index 03711b375431..7afece5bad11 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md @@ -23,7 +23,7 @@ WebDriver可以从弹窗获取文本并接受或关闭这些警告. {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L12-L20" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L13-L19" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -72,7 +72,7 @@ alert.accept() {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L26-L34" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L27-L33" >}} {{< /tab >}} {{< tab header="CSharp" >}} @@ -128,7 +128,7 @@ alert.dismiss() {{< /tab >}} {{< tab header="Python" text=true >}} -{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L40-L49" >}} +{{< gh-codeblock path="/examples/python/tests/interactions/test_alerts.py#L41-L48" >}} {{< /tab >}} {{< tab header="CSharp" >}}