Skip to content

Add Expected Conditions example for Python #2286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2025

Conversation

cgoldberg
Copy link
Contributor

@cgoldberg cgoldberg commented Apr 24, 2025

User description

Description

This PR adds an example for Expected Conditions in Python.

Motivation and Context

Example was missing.

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

(I don't have the GitHub CI Token setup, so I couldn't see the code examples when running hugo)


PR Type

Enhancement, Documentation, Tests


Description

  • Added a Python example for Expected Conditions usage.

  • Updated documentation in four languages to embed the new Python example.

  • Improved test coverage for Selenium Expected Conditions in Python.


Changes walkthrough 📝

Relevant files
Tests
test_expected_conditions.py
Add Python test for Selenium Expected Conditions                 

examples/python/tests/support/test_expected_conditions.py

  • Added a test function demonstrating Expected Conditions in Python.
  • Imported necessary Selenium modules for the example.
  • Provided inline documentation link for Expected Conditions API.
  • +17/-1   
    Documentation
    expected_conditions.en.md
    Embed Python Expected Conditions example in English docs 

    website_and_docs/content/documentation/webdriver/support_features/expected_conditions.en.md

  • Replaced static Python documentation link with embedded code example.
  • Updated tab to use gh-codeblock for Python example.
  • +3/-4     
    expected_conditions.ja.md
    Embed Python Expected Conditions example in Japanese docs

    website_and_docs/content/documentation/webdriver/support_features/expected_conditions.ja.md

  • Replaced static Python documentation link with embedded code example.
  • Updated tab to use gh-codeblock for Python example in Japanese docs.
  • +3/-4     
    expected_conditions.pt-br.md
    Embed Python Expected Conditions example in Portuguese docs

    website_and_docs/content/documentation/webdriver/support_features/expected_conditions.pt-br.md

  • Replaced static Python documentation link with embedded code example.
  • Updated tab to use gh-codeblock for Python example in Portuguese docs.
  • +3/-4     
    expected_conditions.zh-cn.md
    Embed Python Expected Conditions example in Chinese docs 

    website_and_docs/content/documentation/webdriver/support_features/expected_conditions.zh-cn.md

  • Replaced static Python documentation link with embedded code example.
  • Updated tab to use gh-codeblock for Python example in Chinese docs.
  • +3/-4     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    netlify bot commented Apr 24, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit f819f2d

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    Copy link
    Contributor

    qodo-merge-pro bot commented Apr 24, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix element lookup timing

    Finding the element before it's revealed could lead to a NoSuchElementException.
    Move the element lookup after clicking the reveal button and waiting for it to
    be visible.

    examples/python/tests/support/test_expected_conditions.py [10-12]

     driver.get("https://www.selenium.dev/selenium/web/dynamic.html")
    -revealed = driver.find_element(By.ID, "revealed")
     driver.find_element(By.ID, "reveal").click()
     
    +wait = WebDriverWait(driver, timeout=2)
    +revealed = wait.until(EC.visibility_of_element_located((By.ID, "revealed")))
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: The suggestion correctly identifies a critical issue where the test attempts to find an element before it's revealed, which could cause a NoSuchElementException. The improved code properly sequences the operations by clicking first, then waiting, and finally accessing the element after it's visible.

    High
    • Update

    Copy link
    Contributor

    @shbenzer shbenzer left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    LGTM

    @cgoldberg
    Copy link
    Contributor Author

    @harsha509 can you review this?

    Copy link
    Member

    @harsha509 harsha509 left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    LGTM

    Thank you @cgoldberg !

    @harsha509 harsha509 merged commit 46c35d6 into SeleniumHQ:trunk Apr 26, 2025
    9 checks passed
    selenium-ci added a commit that referenced this pull request Apr 26, 2025
    * Add Expected Conditions example for Python
    
    * Remove import and adjust line numbers 46c35d6
    @cgoldberg cgoldberg deleted the py-expected-conditions branch April 27, 2025 15:31
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants