Fifteen common Selenium interview questions
- How does Selenium WebDriver work?
- Which locator strategies do you prefer, and why?
- CSS selectors versus XPath?
- Implicit versus explicit versus fluent waits?
- Why shouldn't you use Thread.sleep?
- How do you handle frames, multiple windows and alerts?
- What is the page object model?
- How do you handle dynamic elements?
- What causes flaky tests, and how do you fix them?
- What is a StaleElementReferenceException?
- How do you run tests in parallel? What is Selenium Grid?
- How do you take screenshots on failure and report results?
- How do you manage test data?
- How do you integrate Selenium tests into CI?
- Selenium versus newer tools such as Playwright or Cypress?
Architecture and locators
- WebDriver sends commands from your test code through a language binding to a browser-specific driver, which controls the browser using the W3C WebDriver protocol.
- Locator priority: stable IDs or dedicated test attributes such as data-testid first, then concise CSS selectors, with XPath for cases CSS can't express, such as matching by text or navigating to a parent.
- Avoid brittle locators tied to layout, such as long absolute XPaths or auto-generated class names.
Waits and flakiness
| Approach | Behaviour | Verdict |
|---|---|---|
| Thread.sleep | Always waits the full time | Slow and still flaky — avoid |
| Implicit wait | Global wait for elements to appear | Simple, but hides problems and mixes badly with explicit waits |
| Explicit wait | Waits for a specific condition, such as clickable | Preferred |
| Fluent wait | Explicit wait with polling interval and ignored exceptions | For unusual conditions |
Flaky tests usually come from timing (acting before the page is ready), shared test data, dependence on test order, unstable locators or environment instability. Fix them with explicit waits on meaningful conditions, independent tests with their own data, stable locators and retries only as a last resort with tracking. StaleElementReferenceException means the element was re-rendered after you found it — locate it again after the page updates.
Framework design
The page object model represents each page or component as a class exposing user-level actions — login(user, password) — and hiding locators, so tests read like scenarios and a UI change requires updating one class. A good framework adds a test runner (JUnit, TestNG or pytest), configuration per environment, test data builders, screenshots and logs on failure, and readable reports. Keep assertions in tests, not page objects.
Scale and CI
- Run tests in parallel with the test runner and Selenium Grid or a cloud browser service for many browsers and machines.
- Run in CI on every merge with headless browsers, a fast smoke suite on pull requests and the full suite nightly.
- Keep the UI suite small and focused on critical journeys; push most checks down to unit and API tests — the testing pyramid.
- Newer tools such as Playwright and Cypress offer auto-waiting and better debugging; Selenium remains strong for broad browser and language support.
A live task to rehearse
“Automate searching a product and adding it to the cart.” Create page objects for the search, results and cart pages; use explicit waits for the results list and the cart badge; assert on user-visible outcomes such as the item name and quantity in the cart; and clean up test data. Talk through how you'd run it in CI and what you'd do if it failed intermittently.
Practising
The fastest way to find gaps is to be asked. Run a spoken mock round on Selenium topics — a free AI interview assistant such as CoPilot Interview builds one from your résumé and the job description and scores every answer — then study whatever you stumbled on. Automate a login with a page object and an explicit wait, then explain how you'd stop it becoming flaky. See also QA engineer interview questions and manual testing interview questions.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly. Everything else on this page applies whichever tool you use, or none.
Frequently asked questions
What are common Selenium interview questions?
WebDriver architecture, locators, CSS versus XPath, waits, frames, windows and alerts, the page object model, dynamic elements, flaky tests, stale elements, Selenium Grid, reporting, test data and CI integration.
Implicit or explicit wait?
Explicit waits, which wait for a specific condition on a specific element. Implicit waits apply globally, hide timing problems and can combine unpredictably with explicit waits.
What is the page object model?
A design pattern where each page or component is a class exposing user actions and hiding locators, making tests readable and limiting changes when the UI changes.
How do you fix flaky Selenium tests?
Replace sleeps with explicit waits, make tests independent with their own data, use stable locators, stabilise the environment and investigate root causes rather than adding blind retries.
Practise on real interview questions
Run 145 real interview questions across 10 tracks, answer out loud and see a structured answer to compare with yours. Free, no signup.
Try a practice question