Bird
0
0

Which sequence of Selenium Java commands correctly switches to frameC and clicks the button with id "btnSubmit"?

hard📝 Application Q15 of 15
Selenium Java - Handling Windows, Frames, and Alerts
You have a webpage with three nested frames: frameA contains frameB, which contains frameC. You want to click a button inside frameC. Which sequence of Selenium Java commands correctly switches to frameC and clicks the button with id "btnSubmit"?
Adriver.switchTo().defaultContent(); driver.switchTo().frame("frameC"); driver.findElement(By.id("btnSubmit")).click();
Bdriver.switchTo().frame("frameC"); driver.findElement(By.id("btnSubmit")).click();
Cdriver.switchTo().frame("frameA"); driver.switchTo().frame("frameB"); driver.switchTo().frame("frameC"); driver.findElement(By.id("btnSubmit")).click();
Ddriver.switchTo().frame("frameA"); driver.switchTo().defaultContent(); driver.switchTo().frame("frameC"); driver.findElement(By.id("btnSubmit")).click();
Step-by-Step Solution
Solution:
  1. Step 1: Switch through each nested frame in order

    Since frameC is inside frameB, which is inside frameA, you must switch step-by-step: first to frameA, then frameB, then frameC.
  2. Step 2: Locate and click the button inside the innermost frame

    After switching to frameC, find the button by id "btnSubmit" and click it.
  3. Final Answer:

    driver.switchTo().frame("frameA"); driver.switchTo().frame("frameB"); driver.switchTo().frame("frameC"); driver.findElement(By.id("btnSubmit")).click(); -> Option C
  4. Quick Check:

    Stepwise frame switching then action = A [OK]
Quick Trick: Switch frames in order from outer to inner before action [OK]
Common Mistakes:
MISTAKES
  • Trying to switch directly to innermost frame
  • Using defaultContent() in middle of switching
  • Not switching frames at all before clicking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes