Use EC.alert_is_present() for Python alert examples#2730
Conversation
Replace implicit lambda workaround with purpose-built expected condition for alert handling in all three Python alert examples. Fixes #2548
Removes the trailing whitespace cgoldberg flagged on PR #2589, and corrects the gh-codeblock line ranges in alerts.en.md, alerts.ja.md, alerts.pt-br.md, and alerts.zh-cn.md. The prior update shifted each range by widening both ends instead of moving by the one 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 <noreply@anthropic.com>
PR Summary by QodoUse EC.alert_is_present() in Python alert examples and align docs snippets
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
✅ Deploy Preview for selenium-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review by Qodo
Context used✅ Compliance rules (platform):
10 rules 1. Docs snippet lacks EC import
|
|
|
||
| {{< 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#L13-L19" >}} |
There was a problem hiding this comment.
1. Docs snippet lacks ec import 🐞 Bug ≡ Correctness
The alert docs embed Python code ranges that include wait.until(EC.alert_is_present()), but those ranges exclude the expected_conditions as EC import that defines EC, so the displayed snippet has an unresolved identifier for readers copying it.
Agent Prompt
## Issue description
The Python alert examples shown via `gh-codeblock` now include `EC.alert_is_present()` but do not show the import that defines `EC`, making the displayed snippet contain an undefined identifier.
## Issue Context
`EC` is introduced only by `from selenium.webdriver.support import expected_conditions as EC` in the source test file, but the doc pages embed only mid-file line ranges that start at the interaction code.
## Fix Focus Areas
Update the docs so that the Python snippet either (a) includes the import lines in the embedded range, or (b) adds a small explicit import snippet/note adjacent to the codeblock in each language page.
- website_and_docs/content/documentation/webdriver/interactions/alerts.en.md[27-35]
- website_and_docs/content/documentation/webdriver/interactions/alerts.ja.md[23-31]
- website_and_docs/content/documentation/webdriver/interactions/alerts.pt-br.md[27-33]
- website_and_docs/content/documentation/webdriver/interactions/alerts.zh-cn.md[20-27]
- examples/python/tests/interactions/test_alerts.py[1-20]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Superseded — the fix (plus the review feedback) has been pushed directly onto #2589 instead. Closing this one. |
Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.
Description
Picks up #2589 (by @beinghumantester): replaces
wait.until(lambda d: d.switch_to.alert)withwait.until(EC.alert_is_present())in all three Python alert examples, and addresses the review feedback that PR didn't get to: removes the trailing whitespace cgoldberg flagged, and fixes thegh-codeblockline ranges inalerts.en.md,alerts.ja.md,alerts.pt-br.md, andalerts.zh-cn.md, which had drifted to includedriver.get(url)and theassertline instead of matching the same scope shown before (and in the other language tabs).Motivation and Context
WebDriverWaitonly ignoresNoSuchElementExceptionby default, notNoAlertPresentException, so the old lambda would raise instead of retrying if the alert hadn't appeared yet on the first poll.EC.alert_is_present()catches that exception internally, so the wait actually retries as intended.Types of changes
Checklist