skip to content

WebDriver Architecture

How a Selenium client actually drives a browser: the HTTP contract it speaks, how a session opens and closes, and where the driver binary comes from. Interviewers probe it for depth past the API.

on this pageshow

explore

questions

page 1 of 2

Where does Selenium Manager store the drivers it downloads, and does every Selenium 4 run download again?

level: juniorimportance: must knowfreq 56%

answer

  1. Downloading every run would be intolerable
  2. A folder under the user's home
  3. Checked before the network is
  4. Versioned sub-folders, no expiry
  5. Default ~/.cache/selenium, moved by SE_CACHE_PATH

basics

~20 s

In a per-user cache folder, by default ~/.cache/selenium, and no. Selenium 4's Selenium Manager reuses a matching cached driver on later runs and downloads only when the cache has no suitable copy. SE_CACHE_PATH moves the folder.

solid answer

~40 s

In Selenium 4, Selenium Manager keeps every driver it fetches in a local **driver cache**, `~/.cache/selenium` by default, laid out in versioned sub-folders it creates itself. Resolution checks that cache before it checks the network, so only the first run on a machine — or a run that needs a driver the cache does not hold — pays for a download; every run after that is a file lookup measured in milliseconds. `SE_CACHE_PATH` relocates the folder, which matters when the account running the bank statement-download suite cannot write to its own home directory. Deleting the folder is the blunt reset: the next run simply resolves and downloads again. Nothing expires the cache on a timer, and nothing cleans it up when a test finishes.

go deeper

for a junior

Remember that downloaded drivers are kept in a cache folder under your home directory and reused, so only the first run pays for a download. Knowing the default path is a bonus.

for a middle

Explain the ordering — cache first, network second — and what SE_CACHE_PATH is for. Be able to say what deleting the folder does and that nothing expires entries on its own.

for a senior

Recognise the cache as a diagnostic surface: per-user ownership, write permissions on the home directory, and whether a given run resolved from disk or the network explain most machine-specific resolution failures.

for a principal

Decide how driver provenance is handled across many machines: whether every host resolves and caches for itself, or drivers are provisioned deliberately, and who is accountable when the two answers disagree.

## Why there is a cache at all **Selenium Manager**, the binary bundled in the Selenium 4 client since **4.6**, exists so a test can construct a driver without anybody having placed an executable first. If that convenience meant a fresh download before every session, the bank statement-download suite would be slower and far more fragile than the manual setup it replaced. The **driver cache** is what makes automatic resolution cheap enough to be the default. The rule is simple: **the cache is checked before the network**. A download is what happens when the cache cannot answer, not what happens on every run. ## Where it lives - The default location is a **per-user folder**, `~/.cache/selenium`, resolved from the home directory of whichever account runs the test. - Inside it, drivers sit in sub-folders keyed by driver and version, a layout Selenium Manager creates and manages itself. - Being per-user matters: two accounts on the same machine keep two caches, and a service account with an unusual or read-only home directory has nowhere to write one. - `SE_CACHE_PATH` (matching the binary's `--cache-path` flag) moves the folder anywhere the running account can write. - Nothing in Selenium removes entries from it. It grows as new driver versions are resolved and stays until something outside Selenium deletes it. ## First run versus every run after | | First run on a machine | A later run, same machine | |---|---|---| | Browser detection | Yes | Yes | | Cache lookup | Miss | Hit | | Network needed | Yes, to download | No | | Typical cost | A download | Milliseconds | | What is written | A new versioned folder | Nothing | That table is the whole answer to the interview question. The cost profile of automatic resolution is *one* download per driver version per cache, not one per run and certainly not one per test. ## Reading, moving and resetting it 1. **Look at it.** The folder is ordinary files; listing it tells you which driver versions the machine has already resolved. 2. **Move it** with `SE_CACHE_PATH` when the home directory is unwritable, ephemeral, or shared in a way you do not control. 3. **Reset it** by deleting the folder. There is no expiry timer and no automatic pruning, so deletion is the reset, and the next run re-resolves from scratch. 4. **Prove which happened** by running the bundled binary with `--debug`, which reports whether the path it returned came from the cache or from a download. ## Where the cache surprises people - A suite that is fast for one engineer and slow for another usually differs only in cache state, not in code. - A permission error on `~/.cache/selenium` presents as a driver-resolution failure rather than as the file-system problem it is; relocating with `SE_CACHE_PATH` fixes it. - Because the cache is per-user, running the suite under a different account is enough to trigger a full re-resolution. - Deleting the cache to "clean up" costs the next run a download; on a machine with no network route out it costs the next run entirely. - `SE_OFFLINE` and the cache are complementary, not alternatives: offline mode forbids the download, and the cache is what lets resolution still succeed. - A machine that has resolved several browser versions over time accumulates several driver versions side by side; that is expected, and old entries are simply never consulted again. ## Why a junior is asked this at all The question looks like trivia about a folder path, but it is really a check on whether a candidate has understood that automatic resolution has a **cost profile**. A candidate who thinks every session downloads a driver will reach for the wrong fixes: they will blame the network for a slow suite, propose committing a driver into the repository, or argue that automatic resolution is too risky to use. A candidate who knows the cache exists reasons correctly about all three. It is also the first place a test author meets the idea that Selenium keeps state **outside the project**. Nothing about the bank statement-download suite's source tree explains why it runs instantly on one machine and pauses on another, and being able to point at a per-user cache folder as the explanation is the whole skill being probed. ## What the cache is not The cache is a resolution accelerator, nothing more. It does not version your test suite, it is not an artefact your build produces, and it holds no session state — once a driver path has been returned, the cache plays no further part in the run. Treat it as a local convenience whose contents can always be rebuilt by resolving again, and it will never be a source of mystery.

  • How would you force Selenium Manager to resolve a driver from scratch?
    Delete the cache folder, `~/.cache/selenium` unless `SE_CACHE_PATH` has moved it. Nothing expires entries on a timer and nothing prunes them automatically, so removing the folder is the reset. The next run detects the browser and downloads again, then repopulates the cache.
  • The suite fails to resolve a driver only when it runs under a service account. What would you check first?
    Whether that account can write to its own `~/.cache/selenium`. The cache is per-user, so a locked-down or read-only home directory surfaces as a driver-resolution failure rather than a permissions error. Pointing `SE_CACHE_PATH` at a writable folder normally settles it.

It behaves like a toolbox drawer rather than a delivery service: the first job sends someone out for the tool, and every job afterwards just opens the drawer.

saying these in an interview costs you the question

  • Says a driver is downloaded before every session
  • Thinks the cache lives in the project directory
  • Believes cached drivers expire automatically after some period
  • Cannot name the environment variable that relocates the cache
  • Assumes one cache is shared by every account on the machine
open as a page

In Selenium 4, what happens when you construct a ChromeDriver without configuring any chromedriver path?

level: juniorimportance: must knowfreq 74%

basics

~20 s

Selenium Manager runs automatically. The binary bundled in the Selenium 4 client detects the installed Chrome, works out the matching chromedriver, downloads it if the local cache lacks it, and returns the path, so the session starts with no PATH entry and no setup code.

open as a page

In Selenium 4, what does setting the `webSocketUrl` capability to true on a new session do?

level: juniorimportance: must knowfreq 64%

basics

~20 s

It asks the remote end to open a WebDriver BiDi socket for that session. If the remote end supports BiDi, the capabilities it returns contain webSocketUrl again, this time as the ws:// address the client connects to.

open as a page

In Selenium 4, what actually happens when a Java test calls new ChromeDriver()?

level: juniorimportance: must knowfreq 85%

basics

~20 s

Constructing ChromeDriver starts a local driver process, waits for it to listen on a free loopback port, then sends it a new-session request. The driver launches the browser and replies with a session id that every later command carries.

open as a page

In Selenium 4, how does a client choose between a configured driver executable and Selenium Manager?

level: middleimportance: must knowfreq 55%

basics

~20 s

An explicitly configured executable wins. If a driver path is set on the service builder or through the webdriver.chrome.driver system property, the Selenium 4 client launches that file; only when nothing is configured does it hand resolution to the bundled Selenium Manager.

open as a page

In Selenium 4, how does a remote end combine alwaysMatch and firstMatch to create a session?

level: middleimportance: must knowfreq 62%

basics

~20 s

The remote end merges alwaysMatch into every firstMatch entry in order and starts the first merged set it can support. A key repeated in both is an error, and no match at all means session not created.

open as a page

In Selenium 4, where does a driver's session id come from and what uses it?

level: middleimportance: must knowfreq 62%

basics

~20 s

The remote end creates it. The client sends a new-session request, the driver opens a browser and replies with an opaque session id. The client stores it and addresses every later command to that id, one session per driver object.

open as a page

Nightly Selenium runs leave chromedriver processes alive on the build host between builds. How do you find and stop that?

level: seniorimportance: must knowfreq 57%

basics

~20 s

A driver service you build and start yourself is yours to stop. Orphans pile up when stop() is skipped on an exception path or the JVM is killed, so pair every start() with a finally, and add a host-level sweep for the kills.

open as a page

A Selenium driver constructor throws in CI — how do you tell which startup stage failed?

level: seniorimportance: must knowfreq 50%

basics

~20 s

Split it by what answered. A connection failure at the driver address means nothing was listening, so no session was requested. A session-not-created error means the endpoint answered and declined. A recorded session id means startup already finished.

open as a page

A Selenium seat-map suite now fails every session with ChromeDriver's 'only supports Chrome version' error - how do you stop it recurring?

level: seniorimportance: must knowfreq 66%

basics

~20 s

ChromeDriver refuses any session whose Chrome major version differs from its own. Pin both halves to one version - a Chrome for Testing build that does not auto-update plus the driver published for it - and upgrade them together.

open as a page

Every Selenium 4 command is a blocking HTTP round trip to the remote end - how does that shape a large suite?

level: principalimportance: must knowfreq 60%

basics

~20 s

Selenium's command protocol is strictly request-response, so every find, click and read costs a full round trip and nothing arrives unasked. Budget commands per case, keep the remote end close, and expect all waiting to be client-side polling.

open as a page

In Selenium 4's WebDriver BiDi, what do event names like `log.entryAdded` and `network.beforeRequestSent` tell you?

level: juniorimportance: should knowfreq 38%

basics

~20 s

Every BiDi name is module dot member. The prefix names the module that owns it, so log owns entryAdded and network owns beforeRequestSent. The same prefixes cover commands, which is how the protocol is organised.

open as a page

Why can't classic WebDriver's HTTP contract in Selenium report a console error at the moment it happens?

level: juniorimportance: should knowfreq 51%

basics

~10 s

Classic WebDriver is client-initiated request and response: the remote end only answers, never speaks first. A browser event can only be asked for afterwards, which is why Selenium 4 adds the BiDi socket.

open as a page

In Selenium 4, which capability keys does a new-session request use to ask for a specific browser?

level: juniorimportance: should knowfreq 68%

basics

~10 s

browserName names the browser, browserVersion asks for a build, platformName asks for an operating system, and acceptInsecureCerts asks to tolerate bad certificates. Any key you leave out places no constraint at all.

open as a page

In Selenium, what does a WebElement object hold, and why is it not a copy of the DOM node?

level: juniorimportance: should knowfreq 60%

basics

~20 s

A WebElement holds an opaque id the driver assigned to a node plus the session that issued it. No markup, text or attributes come with it, so every method call asks the browser again over the wire.

open as a page

In Selenium's WebDriver architecture, what do the terms local end and remote end mean?

level: juniorimportance: should knowfreq 57%

basics

~20 s

The local end is the client library in your test process that turns method calls into commands. The remote end is the driver that receives them and controls the browser. Anything forwarding between the two is an intermediary node.

open as a page

In Selenium, what is ChromeOptions for, and how do you apply it to a new Chrome session?

level: juniorimportance: should knowfreq 74%

basics

~10 s

ChromeOptions is Selenium's typed builder for how a Chrome session starts: launch switches, preferences, extensions and the browser binary. It takes effect only when you pass that instance to the ChromeDriver constructor.

open as a page

In Selenium, what is a ChromeDriverService and why does the Java client need one?

level: juniorimportance: should knowfreq 61%

basics

~10 s

A ChromeDriverService is Selenium's handle on the chromedriver executable. It builds the command line, starts that process, and knows the local HTTP address the Java client sends its WebDriver commands to.

open as a page

In Selenium, what is the difference between calling driver.close() and driver.quit()?

level: juniorimportance: should knowfreq 82%

basics

~20 s

close() shuts only the browser window the driver is focused on and leaves the session running. quit() ends the whole session: every window it owns closes, the browser exits, and the driver process is stopped.

open as a page

In Selenium, what does a session not created error saying ChromeDriver only supports Chrome version 141 mean?

level: juniorimportance: should knowfreq 74%

basics

~10 s

It means the ChromeDriver executable and the Chrome it launched are on different major versions. ChromeDriver drives one Chrome major only, so it rejects the new-session request before any page is loaded.

open as a page

In Selenium 4's WebDriver BiDi, why does a freshly opened socket deliver no events until `session.subscribe` is sent?

level: middleimportance: should knowfreq 48%

basics

~10 s

WebDriver BiDi is subscription-based. Connecting to the socket only establishes the channel; the remote end pushes nothing until the client sends session.subscribe naming the events or modules it wants.

open as a page

In Selenium, what does a Find Element response actually contain, and how does the client use it?

level: middleimportance: should knowfreq 45%

basics

~10 s

Find Element returns a JSON object with one fixed key, element-6066-11e4-a52e-4f735466cecf, holding an opaque id the driver assigned to that node. The client wraps that id in a WebElement; no markup travels back.

open as a page

In Selenium 4's WebDriver protocol, how are command URLs structured around the session id?

level: middleimportance: should knowfreq 66%

basics

~20 s

A POST to /session creates a session and returns its id, every later command is addressed under /session/{session id}/, and a DELETE on that path ends it. The id is a path segment; the remote end holds all the state.

open as a page

In Selenium 4, how do you run Chrome headless now that ChromeOptions.setHeadless() no longer exists?

level: middleimportance: should knowfreq 68%

basics

~10 s

Headless is a browser switch, not a Selenium setting. Build a ChromeOptions, call addArguments with --headless=new, and pass that object to the ChromeDriver constructor. Selenium 4 removed the setHeadless convenience toggle.

open as a page

In Selenium's ChromeOptions and FirefoxOptions, how do browser preferences differ from launch arguments?

level: middleimportance: should knowfreq 57%

basics

~20 s

A launch argument is a command-line switch handed to the browser process at startup; a preference is a setting written into the profile that session runs with. Chrome takes preferences as a map through setExperimentalOption; Firefox has addPreference.

open as a page

In Selenium, which port does ChromeDriverService listen on if you never call usingPort, and how do you pin it?

level: middleimportance: should knowfreq 52%

basics

~10 s

Selenium's driver-service builder picks a port that is free at build time, so every service gets a different one. Call usingPort(9515) to pin a fixed port, or usingAnyFreePort() to state the default choice explicitly.

open as a page

Why does a chromedriver started by Selenium refuse HTTP requests from another machine, and what changes that?

level: middleimportance: should knowfreq 34%

basics

~20 s

The driver executable listens on loopback and rejects non-local clients by default, because anyone who can reach it can drive a browser on that machine. ChromeDriver's --allowed-ips, and geckodriver's --host with --allow-hosts, open it deliberately.

open as a page

Selenium Manager cannot reach the internet on the locked-down host running your bank statement-download suite. How do you make the run succeed?

level: seniorimportance: should knowfreq 38%

basics

~20 s

Give Selenium Manager a driver it already has. Set SE_OFFLINE so it never attempts a download, pre-place the matching driver under the folder named by SE_CACHE_PATH, or configure an explicit driver executable so it is never consulted.

open as a page

In Selenium 4, why does a cross-browser hotel booking-calendar suite prefer WebDriver BiDi to the Chromium-only DevTools bridge?

level: seniorimportance: should knowfreq 42%

basics

~10 s

WebDriver BiDi is a W3C-specified channel that Chromium browsers and Firefox both speak, so one subscription covers the whole matrix. The DevTools bridge is Chromium-only and pinned to browser versions.

open as a page

When a Selenium command carries an element reference, what does the remote end check before answering stale element reference?

level: seniorimportance: should knowfreq 55%

basics

~20 s

The driver looks the opaque id up in its per-browsing-context element cache, then checks two things about the node: that its document is still the active one, and that the node is still attached to that document.

open as a page

showing 1–30 of 40