Bird
0
0

You want to verify text inside a nested frame structure where frame1 contains frame2. You wrote:

hard📝 Application Q9 of 15
Selenium Java - Handling Windows, Frames, and Alerts
You want to verify text inside a nested frame structure where frame1 contains frame2. You wrote:
driver.switchTo().frame("frame1");
String text = driver.findElement(By.id("msg")).getText();

The element with id "msg" is inside frame2. What is the best fix?
AUse <code>driver.switchTo().defaultContent()</code> before finding the element
BChange the locator to find element in frame1
CAdd <code>driver.switchTo().frame("frame2")</code> after switching to frame1 before finding the element
DNo fix needed; code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Identify frame nesting

    The element is inside frame2, which is nested inside frame1, so switching only to frame1 is insufficient.
  2. Step 2: Add switch to inner frame

    After switching to frame1, switch to frame2 before accessing the element.
  3. Final Answer:

    Add driver.switchTo().frame("frame2") after switching to frame1 before finding the element -> Option C
  4. Quick Check:

    Switch all nested frames before element access [OK]
Quick Trick: Switch all nested frames in order to access inner elements [OK]
Common Mistakes:
MISTAKES
  • Trying to find element without switching to inner frame
  • Using defaultContent() which resets focus to main page

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes