Skip to content
TargetQA

Automation Tools

Selenium Interview Questions & Answers

Selenium WebDriver interview questions on locators, waits, page object model, frames and windows, exceptions, Selenium Grid and framework design.

50 questions17 Beginner20 Intermediate13 Advanced

Interview Questions

Showing 15 of 50 questions

  1. Selenium is an open-source suite for automating browsers. Its components are WebDriver for programmatic browser control, Selenium Grid for distributed and parallel runs, and Selenium IDE for record-and-playback.

  2. Client bindings send W3C WebDriver commands over HTTP to a browser driver like chromedriver, which controls the browser natively. Selenium 4 dropped the JSON Wire Protocol, so there is no encoding/decoding layer between client and driver.

  3. Selenium supports id, name, className, tagName, linkText, partialLinkText, cssSelector and xpath. I prefer id or a dedicated data-testid via CSS, then CSS selectors, and use XPath only when I need text matching or traversal.

  4. findElement returns the first matching WebElement and throws NoSuchElementException if none exist. findElements returns a List, which is empty when nothing matches, so it is useful for checking absence.

  5. An implicit wait sets a global timeout for finding elements. An explicit wait (WebDriverWait) waits for a specific condition like visibility or clickability, and a fluent wait is a configurable explicit wait with custom polling and ignored exceptions.

  6. For native select elements I use the Select class with selectByVisibleText, selectByValue or selectByIndex. For alerts I wait for alertIsPresent, switch to the Alert and accept, dismiss or sendKeys.

  7. Use driver.switchTo().frame() by index, name/id or WebElement, and switchTo().defaultContent() to return. For windows, collect getWindowHandles(), switch to the new handle, and switch back using the stored original handle.

  8. The usual ones are NoSuchElementException, StaleElementReferenceException, ElementClickInterceptedException, ElementNotInteractableException and TimeoutException. Most are fixed with correct locators, explicit waits on the right condition, and re-locating elements after DOM changes.

  9. It means the element reference is no longer attached to the DOM, usually after a re-render. I re-locate the element by its By locator after the change, or wait for stalenessOf the old element and then find the new one.

  10. POM gives each page a class that holds its locators and user actions, so tests read like business steps and locator changes are made in one place. PageFactory with @FindBy is still available, but its lazy proxies can cause stale element issues and it is no longer actively recommended by the Selenium team, so many teams use plain By fields instead.

  11. I use annotations like @BeforeMethod/@AfterMethod for driver lifecycle, groups for smoke and regression, @DataProvider for data-driven tests, parallel execution from testng.xml, and listeners for screenshots and reporting.

  12. I store the driver in a ThreadLocal so each test thread gets its own instance, created in setup and quit and removed in teardown. Static shared drivers cause tests to interfere when run in parallel.

  13. I use it for things WebDriver can't do natively, like scrolling to a precise position, reading computed values, or interacting with shadow-root edge cases. I avoid JS clicks as a default because they bypass real user behavior and can hide bugs.

  14. Grid 4 has a Router, Distributor, Session Map, Session Queue and Nodes, and can run in standalone, hub-and-node or fully distributed mode. Tests use RemoteWebDriver with browser options pointed at the Grid URL, and the Distributor assigns sessions to nodes with matching capabilities.

  15. I check failure screenshots, logs and video from CI, then compare environment differences: headless mode, window size, browser version, slower machines and test data. Then I reproduce with the same settings locally, often using the same Docker image.