You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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)
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 pagedriver=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"indriver.page_sourceemail_element=driver.find_element(By.ID, "email")
email_element.send_keys("admin@selenium.dev")
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"indriver.page_sourceemail=driver.find_element(By.ID, "email")
email.send_keys("admin@selenium.dev")
email.clear()
driver.switch_to.default_content()
# --- Switch to iframe using index ---driver.switch_to.frame(0)
assert"We Leave From Here"indriver.page_source# --- Final page content check ---driver.switch_to.default_content()
assert"This page has iframes"indriver.page_source#quit the driverdriver.quit()
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.
# --- 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.
# --- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Checklist
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 📝
test_frames.py
Add Python iframe interaction example scriptexamples/python/tests/interactions/test_frames.py
frames.en.md
Update English iframe documentation with new Python examplewebsite_and_docs/content/documentation/webdriver/interactions/frames.en.md
frames.ja.md
Update Japanese iframe documentation with new Python examplewebsite_and_docs/content/documentation/webdriver/interactions/frames.ja.md
frames.pt-br.md
Update Portuguese iframe documentation with new Python examplewebsite_and_docs/content/documentation/webdriver/interactions/frames.pt-br.md
frames.zh-cn.md
Update Chinese iframe documentation with new Python examplewebsite_and_docs/content/documentation/webdriver/interactions/frames.zh-cn.md