Skip to content
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

added code for frame example for python #2239

Closed

Conversation

pallavigitwork
Copy link
Member

@pallavigitwork pallavigitwork commented Mar 24, 2025

User description

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

added code for frame example for python

Motivation and Context

added code for frame example for python

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.

PR Type

Enhancement, Documentation


Description

  • Added Python code example for iframe interactions in Selenium.

  • Updated documentation to reference the new Python example.

  • Replaced outdated Python code snippets with links to the new example.

  • Improved multilingual documentation consistency for iframe handling.


Changes walkthrough 📝

Relevant files
Enhancement
test_frames.py
Add Python iframe interaction example script                         

examples/python/tests/interactions/test_frames.py

  • Added Python script demonstrating iframe interactions.
  • Includes examples for switching by WebElement, name/ID, and index.
  • Validates iframe content and performs actions like sending keys.
  • Ensures proper cleanup by quitting the driver.
  • +51/-0   
    Documentation
    frames.en.md
    Update English iframe documentation with new Python example

    website_and_docs/content/documentation/webdriver/interactions/frames.en.md

  • Replaced inline Python iframe examples with links to the new script.
  • Updated documentation structure for iframe handling in Python.
  • Improved clarity and consistency in English documentation.
  • +21/-22 
    frames.ja.md
    Update Japanese iframe documentation with new Python example

    website_and_docs/content/documentation/webdriver/interactions/frames.ja.md

  • Replaced outdated Python iframe examples with new script references.
  • Improved Japanese documentation consistency for iframe handling.
  • +19/-24 
    frames.pt-br.md
    Update Portuguese iframe documentation with new Python example

    website_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md

  • Updated Python iframe examples to reference the new script.
  • Enhanced Portuguese documentation for iframe handling.
  • +18/-20 
    frames.zh-cn.md
    Update Chinese iframe documentation with new Python example

    website_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md

  • Replaced inline Python iframe examples with links to the new script.
  • Improved Chinese documentation for iframe handling consistency.
  • +16/-25 

    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 Mar 24, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit de8989e

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Incorrect Frame Selection

    Line 35 locates an iframe by NAME but line 36 uses the previously defined iframe variable instead of the newly located iframe1 variable, which could lead to unexpected behavior.

    iframe1=driver.find_element(By.NAME, "iframe1-name")  # (This line doesn't switch, just locates)
    driver.switch_to.frame(iframe)
    Missing Test Structure

    The file is structured as a script rather than proper test cases with assertions. Consider restructuring using pytest or unittest framework with proper setup/teardown methods.

    #set chrome and launch web page
    driver = webdriver.Chrome()
    driver.get("https://www.selenium.dev/selenium/web/iframes.html")
    
    # --- Switch to iframe using WebElement ---
    iframe = driver.find_element(By.ID, "iframe1")
    driver.switch_to.frame(iframe)
    assert "We Leave From Here" in driver.page_source
    
    email_element = driver.find_element(By.ID, "email")
    email_element.send_keys("[email protected]")
    email_element.clear()
    driver.switch_to.default_content()
    
    # --- Switch to iframe using name or ID ---
    iframe1=driver.find_element(By.NAME, "iframe1-name")  # (This line doesn't switch, just locates)
    driver.switch_to.frame(iframe)
    assert "We Leave From Here" in driver.page_source
    
    email = driver.find_element(By.ID, "email")
    email.send_keys("[email protected]")
    email.clear()
    driver.switch_to.default_content()
    
    # --- Switch to iframe using index ---
    driver.switch_to.frame(0)
    assert "We Leave From Here" in driver.page_source
    
    # --- Final page content check ---
    driver.switch_to.default_content()
    assert "This page has iframes" in driver.page_source
    
    #quit the driver
    driver.quit()

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix variable mismatch

    There's a variable mismatch in the iframe switching code. You're locating an
    element with name "iframe1-name" and storing it in iframe1, but then using the
    previously defined iframe variable when switching frames. Use the iframe1
    variable instead.

    examples/python/tests/interactions/test_frames.py [34-36]

     # --- Switch to iframe using name or ID ---
    -iframe1=driver.find_element(By.NAME, "iframe1-name")  # (This line doesn't switch, just locates)
    -driver.switch_to.frame(iframe)
    +iframe1=driver.find_element(By.NAME, "iframe1-name")
    +driver.switch_to.frame(iframe1)
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: This suggestion fixes a critical bug where the code uses the wrong variable (iframe instead of iframe1) when switching frames, which would cause the test to fail or behave inconsistently. This is a high-impact fix for a clear logical error.

    High
    Add missing frame switch

    After switching to the iframe by index, you should switch back to the default
    content before the final page content check. Add a call to
    driver.switch_to.default_content() after the assertion inside the iframe.

    examples/python/tests/interactions/test_frames.py [44-49]

     # --- Switch to iframe using index ---
     driver.switch_to.frame(0)
     assert "We Leave From Here" in driver.page_source
    +driver.switch_to.default_content()
     
     # --- Final page content check ---
    -driver.switch_to.default_content()
    +assert "This page has iframes" in driver.page_source
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly identifies that the code should switch back to the default content after interacting with the iframe by index, before performing the final page content check. This improves the test's structure and prevents potential state-related issues.

    Medium
    • More

    @pallavigitwork
    Copy link
    Member Author

    putting this PR on hold.

    @pallavigitwork
    Copy link
    Member Author

    created another PR after ensuring local environment is up to date.
    #2240

    @pallavigitwork
    Copy link
    Member Author

    Working on -#2240

    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.

    1 participant