Selenium / Quiz
Switching Contexts: Alerts, Frames, Windows
The element exists, you can SEE it, and Selenium swears it is not there. Welcome to context switching, where most NoSuchElementExceptions are self-inflicted.
- Difficulty
- Easy
- Format
- Quiz
- Points
- 100
- Estimate
- 10 min
// MISSION BRIEF
Your Mission
A payment page embeds its card form in an iframe, opens 3-D Secure in a new tab, and throws a JavaScript confirm() when you cancel. Your test has to survive all three context jumps.
Seven questions on driver.switchTo() in all its forms. Speed bonus active.
// FIRST CONTACT
Battle teaser
The card-number field is inside an <iframe>. driver.findElement throws NoSuchElementException even though the field is clearly visible. Why?
- AIframes require XPath locators
- BThe element must also be focused first
- CThe driver searches only the current browsing context; you must driver.switchTo().frame(...) before locating elements inside the iframe
- DIframes are only supported in headless mode
Answers, scoring, hints, and the full battle stay sealed.
// SKILL TAGS
seleniumiframesalertswindow-handlesweb