Selenium interview questions — Medium
502 medium-level Selenium questions from our Automation Testing bank, each with the correct answer and an explanation of why it is correct.
What this covers
Selenium appears throughout Automation Testing interviews. At medium level, interviewers are typically checking that you have used it in practice: what you configured, what broke, and how you knew it worked. Work through these, then explain your answer out loud; the second part is what interviews actually test.
20 example questions
1. "Switches control to a JavaScript alert/confirm/prompt" — in Selenium, this describes which of the following?
- A. Driver.navigate().back().
- B. Driver.switchTo().alert().correct
- C. Desired capabilities / Options classes.
- D. Driver.quit().
Why: driver.switchTo().alert(): Switches control to a JavaScript alert/confirm/prompt.
2. During a sprint demo, a teammate asks: Which Selenium wait polls the DOM until a condition is met, throwing only on timeout?
- A. Thread.sleep().
- B. Implicit wait.
- C. Explicit wait (WebDriverWait).correct
- D. Page load timeout.
Why: Explicit waits poll until a condition is true or the timeout elapses.
3. "Identifiers used to switch between browser tabs/windows" — in Selenium, this describes which of the following?
- A. Driver.navigate().back().
- B. By.cssSelector.
- C. Window handles.correct
- D. Driver.quit().
Why: window handles: Identifiers used to switch between browser tabs/windows.
4. "Reads the current value attribute of an element" — in Selenium, this describes which of the following?
- A. GetAttribute("value").correct
- B. TakesScreenshot.
- C. By.cssSelector.
- D. Driver.navigate().back().
Why: getAttribute("value"): Reads the current value attribute of an element.
5. "Interface used to capture screenshots during execution" — in Selenium, this describes which of the following?
- A. Driver.findElement(By.id(...)).
- B. Driver.quit().
- C. Driver.close().
- D. TakesScreenshot.correct
Why: TakesScreenshot: Interface used to capture screenshots during execution.
6. "Returns the first element matching the ID locator or throws NoSuchElementException" — in Selenium, this describes which of the following?
- A. Driver.findElement(By.id(...)).correct
- B. By.cssSelector.
- C. TakesScreenshot.
- D. GetAttribute("value").
Why: driver.findElement(By.id(...)): Returns the first element matching the ID locator or throws NoSuchElementException.
7. What does driver.findElements() return when no matching elements are found?
- A. Null.
- B. Throws NoSuchElementException.
- C. An empty list.correct
- D. A single empty WebElement.
Why: findElements() returns an empty List when nothing matches (no exception), whereas findElement() throws NoSuchElementException.
8. Which of the following statements about Selenium is TRUE?
- A. FindElement returns null instead of throwing when no element matches.
- B. Implicit and explicit waits are recommended to be combined for maximum stability.
- C. Selenium Grid can only run tests on a single machine.
- D. Selenium supports Chrome DevTools Protocol (CDP) access in Selenium 4 for network interception and emulation.correct
Why: CDP integration enables capabilities like geolocation override and network throttling.
9. Which statement correctly describes Selenium?
- A. Selenium auto-waits for elements to be actionable before every click, like Playwright.
- B. CSS selectors are generally faster and more readable than complex XPath expressions.correct
- C. A StaleElementReferenceException means the element locator syntax is invalid.
- D. Selenium natively includes a built-in test runner and assertion library.
Why: Most teams prefer CSS selectors; XPath is used for text or axis queries.
10. Identify the accurate statement about Selenium:
- A. Implicit and explicit waits are recommended to be combined for maximum stability.
- B. Selenium auto-waits for elements to be actionable before every click, like Playwright.
- C. Selenium can execute JavaScript in the browser via JavascriptExecutor.correct
- D. A StaleElementReferenceException means the element locator syntax is invalid.
Why: executeScript covers actions the WebDriver API cannot perform directly.
11. "Simulates the browser back button" — in Selenium, this describes which of the following?
- A. Driver.navigate().back().correct
- B. By.cssSelector.
- C. TakesScreenshot.
- D. Driver.findElement(By.id(...)).
Why: driver.navigate().back(): Simulates the browser back button.
12. Which Selenium concept matches this description: "Interface used to capture screenshots during execution"?
- A. ExpectedConditions.elementToBeClickable.
- B. TakesScreenshot.correct
- C. By.cssSelector.
- D. Driver.findElement(By.id(...)).
Why: TakesScreenshot: Interface used to capture screenshots during execution.
13. Which Selenium concept matches this description: "Identifiers used to switch between browser tabs/windows"?
- A. Window handles.correct
- B. Driver.close().
- C. Driver.findElement(By.id(...)).
- D. By.cssSelector.
Why: window handles: Identifiers used to switch between browser tabs/windows.
14. Which Selenium concept matches this description: "Explicit wait that polls until an ExpectedCondition is satisfied"?
- A. Driver.switchTo().alert().
- B. Driver.quit().
- C. Driver.findElement(By.id(...)).
- D. WebDriverWait.correct
Why: WebDriverWait: Explicit wait that polls until an ExpectedCondition is satisfied.
15. Which Selenium concept matches this description: "Returns the first element matching the ID locator or throws NoSuchElementException"?
- A. Desired capabilities / Options classes.
- B. Driver.findElement(By.id(...)).correct
- C. Window handles.
- D. By.cssSelector.
Why: driver.findElement(By.id(...)): Returns the first element matching the ID locator or throws NoSuchElementException.
16. In the context of Selenium, which of the following is a correct statement?
- A. XPath is always faster than CSS selectors in every browser.
- B. Selenium Manager must be installed as a separate pip/npm package.
- C. The Page Object Model separates page structure from test logic to improve maintainability.correct
- D. Selenium can natively automate desktop applications like Excel.
Why: POM keeps locators in one place so UI changes require fewer edits.
17. In Selenium, which of the following is described as: "Configure browser-specific settings such as headless mode"?
- A. Driver.quit().
- B. Desired capabilities / Options classes.correct
- C. WebDriverWait.
- D. TakesScreenshot.
Why: desired capabilities / Options classes: Configure browser-specific settings such as headless mode.
18. In Selenium, which of the following is described as: "Interface used to capture screenshots during execution"?
- A. ExpectedConditions.elementToBeClickable.
- B. TakesScreenshot.correct
- C. Window handles.
- D. WebDriverWait.
Why: TakesScreenshot: Interface used to capture screenshots during execution.
19. In Selenium, which of the following is described as: "Returns the first element matching the ID locator or throws NoSuchElementException"?
- A. Driver.findElement(By.id(...)).correct
- B. Driver.quit().
- C. Driver.navigate().back().
- D. GetAttribute("value").
Why: driver.findElement(By.id(...)): Returns the first element matching the ID locator or throws NoSuchElementException.
20. In Selenium, which of the following is described as: "Switches control to a JavaScript alert/confirm/prompt"?
- A. ExpectedConditions.elementToBeClickable.
- B. Driver.switchTo().alert().correct
- C. WebDriverWait.
- D. Driver.navigate().back().
Why: driver.switchTo().alert(): Switches control to a JavaScript alert/confirm/prompt.