Bird
0
0

You have a page with nested iframes: iframe A contains iframe B. How do you switch to iframe B to click a button inside it?

hard📝 Application Q15 of 15
Selenium Java - Handling Windows, Frames, and Alerts
You have a page with nested iframes: iframe A contains iframe B. How do you switch to iframe B to click a button inside it?
ASwitch to iframe A, then switch to iframe B, then find and click the button.
BSwitch directly to iframe B by its name without switching to iframe A first.
CSwitch to defaultContent(), then switch to iframe B directly.
DSwitch to iframe B using driver.switchTo().parentFrame() twice.
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested iframe structure

    Iframe B is inside iframe A, so you must first switch focus to iframe A.
  2. Step 2: Switch sequentially to nested iframe

    After switching to iframe A, switch again to iframe B to access its elements.
  3. Step 3: Interact with element inside iframe B

    Once focused on iframe B, you can find and click the button.
  4. Final Answer:

    Switch to iframe A, then switch to iframe B, then find and click the button. -> Option A
  5. Quick Check:

    Nested iframe switch = stepwise focus change [OK]
Quick Trick: Switch stepwise through nested iframes before interacting [OK]
Common Mistakes:
MISTAKES
  • Trying to switch directly to nested iframe without parent
  • Using parentFrame() incorrectly to go deeper
  • Not switching to outer iframe first

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes