Bird
0
0

Given the following code snippet, what will be the output?

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

Assuming "innerText" is inside a nested frame within "outerFrame" but not directly inside "outerFrame".
AThrows NoSuchElementException
BPrints the text inside "innerText" element
CPrints empty string
DThrows NoSuchFrameException
Step-by-Step Solution
Solution:
  1. Step 1: Analyze frame switching

    The code switches only to "outerFrame" but tries to find an element inside a nested frame within it.
  2. Step 2: Understand element visibility

    Since "innerText" is inside a nested frame, WebDriver cannot find it without switching to that inner frame first.
  3. Final Answer:

    Throws NoSuchElementException -> Option A
  4. Quick Check:

    Missing inner frame switch causes NoSuchElementException [OK]
Quick Trick: Always switch to correct nested frame before accessing elements [OK]
Common Mistakes:
MISTAKES
  • Assuming switching outer frame is enough to access inner frame elements
  • Expecting empty string instead of exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes