Challenge - 5 Problems
Nested iFrames Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Nested iFrame Text Extraction
What will be the output of the following Selenium Python code that switches to a nested iframe and extracts text?
Selenium Python
from selenium import webdriver from selenium.webdriver.common.by import By # Assume driver is already initialized and navigated to the page driver.switch_to.frame(driver.find_element(By.ID, "frame1")) driver.switch_to.frame(driver.find_element(By.NAME, "frame2")) text = driver.find_element(By.TAG_NAME, "p").text print(text)
Attempts:
2 left
💡 Hint
Remember to switch to each iframe level before accessing elements inside it.
✗ Incorrect
The code correctly switches first to the outer iframe by ID, then to the inner iframe by name, then finds the
tag and extracts its text. This is the correct way to access nested iframe content.
❓ locator
intermediate1:30remaining
Best Locator Strategy for Nested iFrame Element
You need to locate a button inside a nested iframe structure. Which locator strategy is best to find the button element inside the innermost iframe?
Attempts:
2 left
💡 Hint
Remember Selenium cannot find elements inside iframes without switching to them first.
✗ Incorrect
You must switch to each iframe level before locating elements inside. Using a CSS selector with a unique class after switching frames is reliable and clear.
❓ assertion
advanced1:30remaining
Assertion for Text Presence in Nested iFrame
Which assertion correctly verifies that the text 'Welcome' is present inside a nested iframe after switching frames?
Selenium Python
driver.switch_to.frame("outerFrame") driver.switch_to.frame("innerFrame") text = driver.find_element(By.TAG_NAME, "body").text
Attempts:
2 left
💡 Hint
Use Python syntax for substring presence in a string.
✗ Incorrect
In Python, 'in' keyword checks substring presence. Option A is correct syntax and logic. Option A requires exact match, which may fail. Options C and D are invalid syntax or cause errors.
🔧 Debug
advanced1:30remaining
Debugging NoSuchFrameException in Nested iFrames
You get a NoSuchFrameException when running this code snippet. What is the most likely cause?
Selenium Python
driver.switch_to.frame("outerFrame") driver.switch_to.frame("innerFrame") driver.switch_to.frame("nonExistentFrame")
Attempts:
2 left
💡 Hint
Check if the frame name exists inside the current frame context.
✗ Incorrect
NoSuchFrameException means Selenium cannot find the frame with the given name in the current context. The frame 'nonExistentFrame' likely does not exist inside the currently focused frame.
❓ framework
expert2:30remaining
Best Practice for Handling Nested iFrames in Test Framework
In a test automation framework using Selenium Python, what is the best practice to handle nested iframes to improve code maintainability and readability?
Attempts:
2 left
💡 Hint
Think about code reuse and reducing duplication when dealing with nested frames.
✗ Incorrect
Creating reusable functions that accept a list of frame IDs or names to switch sequentially improves maintainability and readability. Inline switching duplicates code, JS injection is fragile, and global variables for elements can cause stale references.