Advanced Selenium Interview Questions
These are the questions that separate someone who has written Selenium tests from someone who has kept a large Selenium suite fast and trustworthy. Expect them for mid and senior roles.
Mid level#
How is Selenium Grid 4 structured?#
Grid 4 was rewritten from scratch. In distributed mode it has six components:
| Component | Job |
|---|---|
| Router | Single entry point. Sends new-session requests to the queue and routes commands for existing sessions straight to the right node. |
| New Session Queue | Holds new-session requests until a slot is free. |
| Distributor | Picks a node with a matching free slot for each queued request. |
| Session Map | Maps each session ID to the node that runs it. |
| Event Bus | Internal messaging between the components. |
| Node | Runs the browsers and drivers. |
You can run it three ways: standalone (everything in one process), hub and node, or fully distributed. Standalone is one command:
java -jar selenium-server-4.52.0.jar standalone
- Follow-up: "Once a session exists, does every command go through the Distributor?" No. The Router asks the Session Map where the session lives and forwards the command to that node.
- Red flag: "Grid makes my tests run in parallel." Grid provides capacity. Parallelism comes from your test runner (TestNG, JUnit 5, pytest-xdist). With a runner that executes one test at a time, a hundred-slot Grid still runs one test at a time.
How do you make a Selenium suite safe to run in parallel?#
Each thread needs its own WebDriver instance, and nothing that belongs to a test may be stored in a static field. The common Java pattern is a ThreadLocal:
public final class DriverFactory {
private static final ThreadLocal<WebDriver> DRIVER = new ThreadLocal<>();
public static void start(Capabilities caps) throws MalformedURLException {
DRIVER.set(new RemoteWebDriver(new URL(System.getenv("GRID_URL")), caps));
}
public static WebDriver get() {
return DRIVER.get();
}
public static void quit() {
WebDriver driver = DRIVER.get();
if (driver != null) {
driver.quit();
DRIVER.remove();
}
}
}
-
Follow-up: "Why
DRIVER.remove()?" Thread pools reuse threads; without it the next test on that thread can see a dead driver. - Also expected: test data isolation. Two parallel tests that log in as the same user and edit the same cart will fail randomly no matter how good your driver handling is.
What is Selenium Manager?#
Since Selenium 4.6, the bindings ship with Selenium Manager, a small binary that finds the right driver for the installed browser and downloads it if needed. Later releases also let it download the browser itself (Chrome for Testing, Firefox, Edge) when none is found or a specific version is requested.
- Follow-up: "When would you still set the driver path yourself?" Locked-down build agents without internet access, or when your company mirrors binaries internally.
-
Red flag: Not knowing it exists and adding WebDriverManager plus a
System.setPropertycall to a new project.
Senior level#
What is WebDriver BiDi, and how does it relate to CDP?#
Classic WebDriver is request/response over HTTP: the test asks, the browser answers. WebDriver BiDi is a W3C protocol over a WebSocket, so the browser can push events to the test: console messages, JavaScript errors, network requests. The Chrome DevTools Protocol (CDP) offered similar features earlier, but only for Chromium browsers, and Selenium's CDP support is tied to specific Chrome versions. BiDi is the cross-browser, standardised replacement, and the Selenium project is moving its high-level APIs onto it.
ChromeOptions options = new ChromeOptions();
options.setCapability("webSocketUrl", true); // opt in to BiDi
WebDriver driver = new ChromeDriver(options);
try (LogInspector logs = new LogInspector(driver)) {
logs.onJavaScriptException(entry ->
System.out.println("JS error: " + entry.getText()));
driver.get("https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html");
driver.findElement(By.id("jsException")).click();
}
LogInspector lives in org.openqa.selenium.bidi.module. On a remote grid the same webSocketUrl capability applies; the Selenium BiDi documentation for TestingBot shows the remote setup in six languages.
- Follow-up: "Give me a real use for it." Fail any test that throws an uncaught JavaScript error, even when the UI assertion passed.
- Red flag: "BiDi replaces WebDriver." It extends it; both are used in the same session.
A test passes locally and fails 1 in 20 runs in CI. How do you diagnose it?#
Interviewers want a method, not a guess:
- Reproduce: run it 50 to 100 times in a loop, in the CI environment, ideally in parallel with the rest of the suite.
- Collect evidence: screenshot, video, browser console, network log and driver log from the failing run.
- Classify the cause: timing (missing wait, animation), test-data collision, test-order dependency, environment (slower CI machine, different viewport, missing font), or a genuine product bug that only shows under load.
- Fix the cause, not the symptom. Retries are a reporting tool, not a fix.
- Quarantine if it cannot be fixed today, with a ticket and an owner, so the rest of the suite stays trusted.
Our article on handling test flakiness goes deeper into each category. The scenario chapter turns this into a full interview scenario.
How would you structure a Selenium framework for a team of ten?#
Describe layers and the reason for each:
-
Tests read like specifications and contain no locators.
-
Page objects or components own locators and expose user actions (
loginAs(user)), returning the next page object. The Page Object Model course covers the pattern in depth. -
Driver management in one place (factory plus
ThreadLocal), configured by environment variables: browser, version, grid URL. -
Test data created through APIs, unique per test, cleaned up afterwards.
-
Reporting that attaches artifacts on failure.
-
CI runs a fast smoke set on every pull request and the full matrix nightly.
-
Red flag: "I put all locators in an Excel sheet and a keyword engine reads them." Some companies do this; defend it only if you can explain who maintains it and how it is reviewed.
How do you handle Shadow DOM?#
Selenium 4 exposes the shadow root directly:
WebElement host = driver.findElement(By.cssSelector("user-profile"));
SearchContext shadow = host.getShadowRoot();
shadow.findElement(By.cssSelector("button.save")).click();
Use CSS selectors inside the shadow root; XPath does not cross shadow boundaries.
-
Follow-up: "What about nested shadow roots?" Call
getShadowRoot()again on the inner host.