Selenium interview questions and answers
Selenium interview questions test whether you can drive a real browser reliably with WebDriver: how a command travels from your code to the browser, which locator to choose, why explicit waits beat sleeps, how the Page Object Model keeps a suite maintainable, and how Grid runs tests in parallel. Freshers are asked about locators, waits and basic commands; experienced testers get flaky tests, framework design and Selenium 4 questions.
By Evin JohnPublished 9 min read
What Selenium interviews look like
Selenium appears in many automation tester and SDET job posts, so the questions go deep. A typical loop has a screening call about your current framework, a concepts round on WebDriver, locators and waits, and a hands-on task: write a locator for an element on a page they share, automate a login or search flow, or fix a test that fails one run in five. Senior candidates also walk through a framework they built, covering how it is structured, how it runs on Grid or in a cloud browser service, and how failures are reported. Java with TestNG or JUnit is a common stack in these rounds, and Python and C# come up too.
WebDriver architecture and basics
| Question | What it tests | What a strong answer shows |
|---|---|---|
What happens when you call driver.findElement(...)? | Architecture | The language binding turns the call into a W3C WebDriver HTTP request, the browser driver (chromedriver, geckodriver, msedgedriver) receives it and executes it in the browser, and the response travels back as JSON. |
| Selenium WebDriver, IDE and Grid: what is each for? | Suite components | WebDriver is the API for controlling browsers from code. IDE is a browser extension for record and playback. Grid runs WebDriver sessions on remote machines, in parallel and across browsers. |
| Why does each browser need its own driver? | Architecture | Each vendor implements the WebDriver standard for its own browser. The driver is the server that translates standard commands into that browser's internals. |
findElement versus findElements? | API basics | findElement returns the first match or throws NoSuchElementException. findElements returns a list, empty if nothing matches, which makes it the safe way to check that something is absent. |
driver.close() versus driver.quit()? | Sessions | close shuts the current window. quit ends the whole session and stops the driver process. Forgetting quit leaves browser processes running on CI agents. |
driver.get() versus driver.navigate().to()? | Navigation | Both load a URL and wait for the page load strategy. navigate() also gives you back, forward and refresh. |
| How do you handle a dropdown? | Common controls | For a native <select>, the Select class with selectByVisibleText or selectByValue. Custom dropdowns built from divs need a click to open and a locator for the option. |
| How do you handle alerts, frames and new windows? | Context switching | switchTo().alert() to accept or read an alert, switchTo().frame(...) and back with defaultContent(), and window handles with getWindowHandles() to switch tabs. |
| How do you upload a file? | Practical | Send the absolute file path with sendKeys to the <input type="file">. The OS file dialog is outside the browser and WebDriver cannot drive it. |
| Can Selenium test a desktop app or a CAPTCHA? | Limits | No. It drives browsers only, and CAPTCHAs exist to stop automation; test environments disable them or use test keys. |
Locator questions
- Which locator strategy do you try first? A unique, stable ID or a dedicated test attribute such as
data-testid, then a short CSS selector. Long chains copied from the browser's dev tools break with the first layout change. - CSS selector or XPath? CSS is shorter and widely used for most lookups. XPath can match on visible text and move up to a parent or across to a sibling, which CSS cannot.
- Absolute or relative XPath? Absolute XPath (
/html/body/div[2]/...) breaks when anything above the element changes. Relative XPath (//button[normalize-space()='Save']) anchors on what makes the element unique. - How do you locate an element whose ID changes on every load? Match the stable part with
contains()orstarts-with()in XPath or[id^='order-']in CSS, or anchor on a nearby label and walk with axes such asfollowing-sibling. - Which XPath axes do you actually use?
ancestorto reach a row from a cell,following-siblingto get the value next to a label, andparentwith..for the container of a known element. - How do you locate the price in the row that contains a given product name? Find the row by its text, then the cell inside it, for example
//tr[td[normalize-space()='Blue mug']]/td[@class='price']. - What are relative locators? A Selenium 4 feature that finds an element by its position relative to another one:
above,below,toLeftOf,toRightOfandnear. They help on forms without good attributes but depend on layout, so screen size can change the result. - How do you reach an element inside a shadow DOM? Normal locators do not cross a shadow root. Get the host element, call
getShadowRoot(), and search inside it with a CSS selector.
Waits and synchronization
| Question | What it tests | What a strong answer shows |
|---|---|---|
| Implicit, explicit and fluent waits: what is the difference? | Waits | Implicit wait is a global timeout applied to every element lookup. Explicit wait (WebDriverWait) waits for a specific condition on one element. Fluent wait is an explicit wait where you also set the polling interval and which exceptions to ignore. |
| Why not mix implicit and explicit waits? | Waits | The documentation warns against it because the timeouts interact unpredictably: an explicit wait that polls findElement can sit through the implicit timeout on every poll, so total wait time is hard to reason about. |
What is wrong with Thread.sleep(5000)? | Test design | It always waits the full time, slowing the suite, and still fails when the app takes six seconds. Waiting on a condition finishes as soon as it is true. |
| Which expected conditions do you use most? | API | visibilityOfElementLocated, elementToBeClickable, invisibilityOfElementLocated for spinners, textToBePresentInElementLocated, urlContains and numberOfWindowsToBe. |
What causes StaleElementReferenceException? | DOM lifecycle | The element you found was removed or replaced, often by a re-render after an update. Store locators instead of elements and look the element up again after the action that changes the page. |
What does ElementClickInterceptedException mean? | Debugging | Something else would receive the click: an overlay, a sticky header, a toast or a loading mask. Wait for it to disappear or scroll the target into view; do not jump straight to a JavaScript click, which hides real bugs. |
NoSuchElementException versus TimeoutException? | Exceptions | The first comes from a lookup that found nothing. The second comes from an explicit wait whose condition never became true within the timeout. |
| What is the page load strategy? | Navigation | normal waits for the full load event, eager returns once the DOM is ready, none returns at once. Single-page apps keep loading data after either, which is why element waits still matter. |
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginPage {
private final WebDriver driver;
private final WebDriverWait wait;
private final By email = By.id("email");
private final By password = By.id("password");
private final By submit = By.cssSelector("button[type='submit']");
private final By error = By.cssSelector("[role='alert']");
public LoginPage(WebDriver driver) {
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
public LoginPage open(String baseUrl) {
driver.get(baseUrl + "/login");
wait.until(ExpectedConditions.visibilityOfElementLocated(email));
return this;
}
public LoginPage submitCredentials(String user, String pass) {
type(email, user);
type(password, pass);
wait.until(ExpectedConditions.elementToBeClickable(submit)).click();
return this;
}
public String errorMessage() {
return wait.until(ExpectedConditions.visibilityOfElementLocated(error)).getText();
}
private void type(By locator, String text) {
WebElement field = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
field.clear();
field.sendKeys(text);
}
}Wait<WebDriver> fluent = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofMillis(500))
.ignoring(NoSuchElementException.class);
WebElement status = fluent.until(d -> {
WebElement el = d.findElement(By.id("export-status"));
return el.getText().equals("Ready") ? el : null;
});Page Object Model and framework questions
- What is the Page Object Model and why use it? One class per page or component holds its locators and the actions a user can take there. When the UI changes you fix one class instead of fifty tests, and tests read as user steps.
- Should page objects contain assertions? Most teams keep assertions in tests and let page objects return data or the next page object. That keeps pages reusable for positive and negative tests.
- What is Page Factory, and do you still use it? A Java helper that fills
@FindByfields with lazy proxies. Many teams now prefer plainByfields with explicit waits, since the proxies can hide stale element problems and add little. - How do you share one driver across page objects without static globals? Pass it in through constructors. For parallel runs, keep one driver per thread, often with a
ThreadLocalin Java, so tests never share a browser. - How do you take a screenshot when a test fails? Cast the driver to
TakesScreenshotin a TestNG listener or JUnit extension, save the file with the test name, and attach it to the report. Selenium 4 can also screenshot a single element. - When do you use the `Actions` class? For hover menus, drag and drop, right clicks, key combinations and click-and-hold. It builds a sequence of low-level input actions.
- When is `JavascriptExecutor` acceptable? For scrolling, reading values the UI does not show, or setting up state. Clicking or typing through JavaScript skips the checks a real user hits, so it should not replace normal interactions in tests.
- How do you run the same test with several data sets? TestNG
@DataProvider, JUnit 5@ParameterizedTest, or pytest parametrize in Python, reading from code, CSV or JSON. The automation testing questions cover data-driven framework design in general.
Selenium Grid and parallel runs
- How does a test run on Grid? You create a
RemoteWebDriverwith the Grid URL and browser options. Grid routes the new session request to a node that has a matching browser, and every command after that goes to the same session. - What are the parts of Grid in Selenium 4? Router, distributor, session map, new session queue, event bus and nodes. You can run them all in one process (standalone), as hub and nodes, or fully distributed.
- How do you run Grid in containers? The official docker-selenium images provide standalone browsers and node images, often started together with Docker Compose for local and CI runs.
- Grid or a cloud browser service? Your own Grid costs maintenance but keeps data and network access in house. A cloud service gives many browser and OS combinations and real mobile devices without running infrastructure.
- What breaks when tests run in parallel? Shared test users, shared data, static drivers and tests that depend on order. Each test should create or own the data it needs.
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new", "--window-size=1366,768");
WebDriver driver = new RemoteWebDriver(URI.create("http://grid.internal:4444").toURL(), options);
try {
driver.get("https://shop.example.com");
WebElement total = driver.findElement(RelativeLocator.with(By.tagName("span")).toRightOf(By.id("total-label")));
System.out.println(total.getText());
} finally {
driver.quit();
}Selenium 4, flaky tests and senior scenarios
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What changed in Selenium 4? | Currency | Full W3C WebDriver protocol, relative locators, switchTo().newWindow() for tabs and windows, element screenshots, a rebuilt Grid, access to Chrome DevTools features and growing WebDriver BiDi support. Later 4.x releases added Selenium Manager, which finds or downloads the right driver for you. |
| A test fails one run in ten. How do you find out why? | Flakiness | Re-run it in a loop, capture screenshots, browser logs and timing on failure, then check the usual browser-level causes: missing waits, animations, stale elements, overlays, window size and data shared with other tests. |
| Tests pass locally and fail in headless CI. What differs? | Environment | Window size and layout breakpoints, fonts, slower machines, a different browser version, and missing downloads or permissions. Set an explicit window size and log the browser version in every run. |
| How do you test a page that loads data after the page load event? | SPA timing | Wait for the element or text that shows the data arrived, or for a loading spinner to disappear, rather than relying on page load. |
| How would you capture network calls or console errors? | Selenium 4 tooling | Use the DevTools or BiDi APIs available for Chromium-based browsers, or route traffic through a proxy. Keep this optional so cross-browser runs still work. |
| Selenium, Cypress or Playwright for a new project? | Judgment | Selenium for the widest browser and language coverage and existing Grid setups; Cypress or Playwright for faster feedback in JavaScript-heavy teams. See the Cypress comparison. |
| How do you keep a 2,000-test suite fast? | Scale | Move checks that do not need a browser down to API and unit tests, run in parallel on Grid, set up state through APIs instead of the UI, and split smoke and full regression runs. |
Fictional example
- Interviewer
- The checkout test fails about once a day with a stale element error when it clicks Place order. How do you approach it?
- Candidate
- Stale means the element I found earlier is no longer in the DOM, so something re-rendered between finding it and clicking it. In a checkout that is usually the order summary refreshing after shipping costs come back. First I would look at the page object: if it stores the
WebElementin a field or finds the button before choosing shipping, that is the bug. I would store theBylocator instead and look it up right before the click. Then I would wait for the thing that causes the re-render to finish, for example the shipping total to show a value or the summary spinner to disappear, followed byelementToBeClickableon the button. I would not wrap the click in a retry loop that catches the exception, because that hides a real timing problem. To confirm the fix, I would run the test fifty times in a loop on the CI machine type and attach a screenshot and timing log to any failure.
How to prepare for a Selenium interview
- Write locators on real pagesOpen a busy public site and write CSS and XPath for twenty elements, including a table cell found by its row text and a field found by its label.
- Build a small frameworkAutomate login, search and checkout on a demo shop with page objects, explicit waits, a data provider and screenshots on failure.
- Break it on purposeAdd an implicit wait next to explicit ones, store a stale element, remove a wait, and note the exception and how you diagnosed each.
- Run it on GridStart a standalone Grid in a container, point the suite at it, and run two browsers in parallel.
- Prepare the framework walkthroughBe ready to draw your framework's layers and explain reporting, CI triggers, parallel runs and how you handle test data.
Selenium interviews often sit inside a wider QA or developer loop. The manual testing questions cover test design and bug reporting, and software engineer interview questions cover the coding rounds an SDET may also face.
When you rehearse a framework walkthrough, it helps to hear where you skipped steps. Natively, an AI interview assistant that runs on Mac and Windows, records a transcript of a mock Selenium round so you can check whether you explained your wait strategy or just named it. During practice it can read a screenshot of a stack trace or a page you need a locator for and suggest an approach, help you work through Java or Python code, and, with Pro or the free trial, use the résumé and job description you add. Notes and transcripts are there to review after each session.
Questions people ask
What Selenium questions are asked in interviews?
How WebDriver talks to the browser, locator strategies and XPath, implicit versus explicit versus fluent waits, common exceptions, the Page Object Model, handling frames and windows, Grid and what changed in Selenium 4.
What is the difference between implicit and explicit waits in Selenium?
An implicit wait is a global timeout for every element lookup. An explicit wait waits for one specific condition, such as an element being clickable. Use explicit waits and avoid mixing the two.
What Selenium questions do experienced testers get?
Flaky test diagnosis, StaleElementReferenceException, framework design with page objects, parallel runs on Grid, CI failures that do not happen locally, and when Selenium is or is not the right tool.
Which language is best for a Selenium interview?
Use the language the team uses. Java with TestNG or JUnit is common in Selenium roles, and Python, C# and JavaScript bindings are also widely used.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
