Bird
0
0

Given the following code snippet, what will be printed?

medium📝 Predict Output Q13 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Given the following code snippet, what will be printed?
driver.switchTo().frame("outerFrame");
driver.switchTo().frame("innerFrame");
String text = driver.findElement(By.id("message")).getText();
System.out.println(text);

Assuming the element with id "message" inside "innerFrame" contains "Hello Nested Frames".
A"Hello Nested Frames"
BNoSuchElementException
CEmpty string
DStaleElementReferenceException
Step-by-Step Solution
Solution:
  1. Step 1: Switch to outer then inner frame

    The code correctly switches first to "outerFrame", then to "innerFrame" where the element exists.
  2. Step 2: Locate element and get text

    Since the element with id "message" is inside "innerFrame", getText() returns "Hello Nested Frames".
  3. Final Answer:

    "Hello Nested Frames" -> Option A
  4. Quick Check:

    Correct frame switching finds element text = D [OK]
Quick Trick: Switch frames stepwise to access nested elements [OK]
Common Mistakes:
MISTAKES
  • Not switching to inner frame before accessing element
  • Trying to find element in default content
  • Confusing exception types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes