Replace implicit lambda workaround with EC.alert_is_present in Python alert examples (Fixes #2548)#2589
Conversation
Replace implicit lambda workaround with purpose-built expected condition for alert handling in all three Python alert examples. Fixes SeleniumHQ#2548
✅ Deploy Preview for selenium-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
There was a problem hiding this comment.
Since this adds an import and shifts the line numbers, the codeblocks in the example page need to be adjusted to match.
The line numbers that need to be changed are in:
website_and_docs/content/documentation/webdriver/interactions/alerts.en.md (and alerts.ja.md, alerts.pt-br.md, alerts.zh-cn.md)
Other than that, I think this change is fine.
|
@beinghumantester please make the suggested changes and update your branch if you want this merged. |
|
I have updated the Python codeblock line references in alerts.en.md, alerts.ja.md, alerts.pt-br.md, and alerts.zh-cn.md so the rendered snippets match the modified example file. Please take another look when you have time. |
Code Review by Qodo
Context used✅ Compliance rules (platform):
10 rules 1.
|
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 <noreply@anthropic.com>
|
Code review by qodo was updated up to the latest commit c5b7ae5 |
|
Code review by qodo was updated up to the latest commit bf8608e |
User description
Description
Replaces the implicit lambda-based alert wait with the purpose-built
EC.alert_is_present()expected condition in all three Python alert examples.The previous implementation used:
This has been updated to:
Motivation and Context
The examples previously used a lambda workaround to wait for alerts. While functional, Selenium provides a dedicated expected condition specifically designed for this use case.
Using
EC.alert_is_present():All three Python alert examples have been updated: Alert, Confirm, and Prompt.
Files Reviewed but Intentionally Not Changed
test_expected_conditions.pyContains
wait.until(lambda _ : revealed.is_displayed())— left unchanged because no EC equivalent exists for an already-located element.EC.visibility_of_element_located()requires a locator tuple, not an existingWebElement.test_waits.pyContains two lambdas, both intentionally left unchanged:
lambda _ : revealed.is_displayed()— same reasoning as abovelambda _ : revealed.send_keys("Displayed") or True— custom condition that performs an action and returnsTrue. No direct EC equivalent exists for this pattern.Types of Changes
Checklist
PR Type
Enhancement
Description
Replace lambda workaround with
EC.alert_is_present()in Python alert examplesAdd import for
expected_conditionsmoduleImproves code readability and aligns with Selenium best practices
Updates all three alert test cases (Alert, Confirm, Prompt)
Diagram Walkthrough
File Walkthrough
test_alerts.py
Replace lambda alert waits with EC.alert_is_present()examples/python/tests/interactions/test_alerts.py
expected_conditionsmodule fromselenium.webdriver.supportEC.alert_is_present()intest_alert_popup()EC.alert_is_present()intest_confirm_popup()EC.alert_is_present()intest_prompt_popup()