ScreenshotNeo

BlogEngineering

Selenium 4 WebDriver Architecture: A Practical Guide

Follow Selenium 4 commands from a language binding to a local browser or Selenium Grid, and learn where Selenium Manager and WebDriver BiDi fit.

By the ScreenshotNeo team4 October 202611 min read

Selenium 4 is a layered browser automation system. Your test calls a language binding such as Python or Java; the binding sends WebDriver commands to a browser-specific driver locally or to a remote Selenium server. For remote runs, Selenium Grid routes a new session to a compatible Node and sends later commands to the Node that owns that session. Selenium Manager can handle much of local browser-driver setup, while WebDriver BiDi adds a separate WebSocket channel for browser events.

The usual WebDriver command path is based on the W3C WebDriver protocol. It is inaccurate to describe ordinary Selenium 4 WebDriver traffic as only the legacy JSON Wire Protocol. The W3C has a WebDriver Recommendation and continues work in a later Working Draft. W3C WebDriver status

1. The layers in Selenium 4

Think of the architecture as a client, a protocol, and a remote end. The remote end may be a local browser driver or a remote Selenium server. Grid adds a scheduling and routing layer when sessions run across machines.

Layer What it does
Test code Expresses actions and assertions, such as navigating to a URL or finding an element.
Language binding Provides the language-facing API and turns calls into WebDriver commands.
WebDriver protocol Defines how a local end sends commands to a remote end and receives responses.
Browser driver / remote end Implements commands and interacts with the browser or its browser-specific automation endpoint.
Browser Loads and renders the page and performs the requested browser actions.
Selenium Grid (optional) Allocates remote sessions to Nodes and routes commands to the Node running a session.

The W3C describes WebDriver as a platform- and language-neutral interface for inspecting and controlling a browser. Selenium’s overview describes WebDriver as driving browsers natively through browser-vendor automation APIs. The binding is the API your test author uses; it is not itself the browser.

2. Local WebDriver command flow

  1. Your test constructs a driver through a Selenium language binding and supplies browser options.
  2. The binding starts or connects to the local browser-specific driver endpoint. Selenium Manager may resolve and obtain the needed browser driver in supported environments.
  3. The binding sends WebDriver commands to that endpoint, which controls the browser.
  4. The endpoint returns responses; the binding exposes them as language-level results or exceptions.

For a basic local Python script, a separate Selenium Server is not required. A server is needed when you choose remote execution, such as a Grid. The exact browser and binding availability depends on the current Selenium release and your environment; consult the relevant binding documentation before standardizing a CI image.

Runnable local Python example

Install the Selenium package in your environment, then save and run this script. In a typical supported setup, Selenium Manager handles driver management when the driver is created.

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
# options.add_argument("--headless")  # Enable for headless environments.

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    print("Title:", driver.title)
    heading = driver.find_element(By.TAG_NAME, "h1")
    print("Heading:", heading.text)
finally:
    driver.quit()

Use browser options for browser-specific behavior such as headless mode. Keep the driver lifecycle in a try/finally block so a failure does not leave a browser session running.

3. RemoteWebDriver and Selenium Grid

Use RemoteWebDriver when the browser should run on another machine or be allocated by Grid. The client sends a new-session request to the Grid URL with browser options or capabilities. Grid chooses a matching slot; after the session starts, commands are routed to the Node that owns it.

Grid’s six component roles

Component Role
Router The entry point for clients. It routes new-session requests and, for an established session, forwards commands to the owning Node.
New Session Queue Holds session requests that have not yet been assigned to a slot.
Distributor Looks for a compatible available slot and assigns a queued request to a Node.
Node Provides slots and runs browser sessions.
Session Map Tracks which Node owns each active session so commands can be routed correctly.
Event Bus Carries asynchronous events between Grid components.

A slot is a place where one session may run. Its stereotype describes the minimum capabilities a request must match. A Node can advertise multiple browser slot types, while its maximum-session setting independently limits concurrency. The Distributor works from a scheduling model that can briefly differ from actual Node state during startup or changes; do not treat it as a perfect, instantaneous inventory.

Grid communication is not one long synchronous HTTP chain. WebDriver calls that need a response use synchronous REST-like JSON over HTTP, while the Event Bus broadcasts asynchronous information where a response is not needed for the operation to proceed.

Runnable RemoteWebDriver Python example

Start a Selenium Grid using the current Grid getting-started instructions, then use its configured URL below. The example assumes the Grid can accept a Chrome session and that the client can reach its endpoint.

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
# options.add_argument("--headless")

driver = webdriver.Remote(
    command_executor="http://localhost:4444",
    options=options,
)
try:
    driver.get("https://example.com")
    print("Title:", driver.title)
    print("Session ID:", driver.session_id)
    print("Browser:", driver.capabilities.get("browserName"))
finally:
    driver.quit()

The URL and topology are deployment choices. Grid’s documented quick-start ports and commands may change, so copy them from the current setup documentation rather than relying on old examples. In a distributed deployment, configure component addresses, network access, browser capacity, and observability deliberately.

4. How Grid routes a session

  1. The client submits a new-session request to the Router with desired browser capabilities.
  2. The Router sends the request to the New Session Queue.
  3. The Distributor examines queued requests and its slot model to find a Node slot whose stereotype matches the request.
  4. The selected Node creates the session and returns session details.
  5. The Session Map records the session-to-Node ownership.
  6. For subsequent commands, the Router uses that mapping to send each command to the correct Node.

If there is no compatible free slot, the request remains queued until a slot becomes available or the request times out. A mismatch can be about browser name, platform, or another requested capability. A slot being present does not imply unlimited parallelism: the Node’s maximum sessions and actual resources also constrain execution.

5. Selenium Manager and driver setup

Selenium Manager is implemented in Rust and is used by Selenium bindings by default to automate much of browser and driver management. In ordinary local use, creating a WebDriver often works without separately downloading a driver binary. That convenience is not a guarantee in every environment.

Manual setup remains useful when an environment is locked down, offline, customized, or requires pinned browser and driver versions. Automated resolution can simplify routine setup; explicit configuration can make version selection and image contents more controlled. The right choice depends on whether convenience or a tightly managed runtime is the stronger requirement.

  • Try Selenium Manager first for a standard developer workstation or a supported CI environment with the required network access.
  • Manage binaries and versions explicitly when the environment cannot download dependencies, must use an approved mirror, or needs a reproducible browser-driver pairing.
  • Check the binding documentation for the current configuration mechanism and supported browsers.

6. WebDriver BiDi: the event channel

Classic WebDriver commands follow a request/response pattern: the client asks the remote end to do something and receives a result. WebDriver BiDi adds a WebSocket-based bidirectional channel that lets automation subscribe to and react to browser events, including network activity, console messages, and JavaScript errors.

BiDi complements the classic command path; it does not mean every WebDriver command has become an event. Selenium’s documentation characterizes BiDi as a cross-browser replacement for Chrome DevTools Protocol, but browser and binding coverage should be checked for the exact feature you need. The protocol and implementation state continue to evolve. See the Selenium WebDriver BiDi documentation.

7. Choosing local execution or Grid

Consideration Local WebDriver Grid
Where browser runs On the machine running the test. On a Grid Node, potentially another machine.
Browser and OS coverage Limited to browsers and platforms available locally. Can cover different machines, operating systems, and browser combinations.
Parallel capacity Limited by the local machine and test setup. Can allocate sessions across configured Nodes and slots.
Operations Fewer services to configure and protect. Requires deployment, capacity management, and network controls.
Version control Manage the local browser and driver environment. Manage browser versions and Node images across the Grid.
Placement diagnosis Execution location is apparent. Inspect Grid session and Node information to diagnose placement.

Grid is appropriate when tests need platform and browser combinations or parallel capacity across machines. Local execution keeps the system simpler when one machine’s available browsers are sufficient. Grid adds operational work and a network-facing endpoint that needs protection.

8. Protecting WebDriver and Grid endpoints

A WebDriver endpoint can create and control browser sessions. Do not expose an unauthenticated endpoint broadly to a network. Restrict access to the client systems that need it, expose only the necessary Grid entry point, and follow current Selenium deployment guidance.

The May 2026 W3C Working Draft suggests loopback-only connections by default to reduce the risk of arbitrary machines creating browser sessions, and discusses limiting accepted IP ranges. This is guidance in a Working Draft, not a finalized normative requirement. Apply network restrictions appropriate to your deployment regardless, and consult the current draft text for its status and details.

9. Troubleshooting common failures

Symptom Likely cause What to check or fix
Driver executable cannot be found or started Driver setup failed, or the browser and driver environment is unavailable or incompatible. Check Selenium Manager’s ability to access the required resources. For offline or controlled systems, configure the browser and driver explicitly using the current binding documentation.
Browser fails to start in CI The environment lacks a usable browser, has incompatible runtime settings, or needs headless configuration. Confirm the browser is installed and supported in the image; configure browser options for that environment and inspect the browser startup error.
Connection refused to the remote server Grid is not running at the configured address, the port differs, or routing/firewall rules prevent access. Verify the current Grid topology and endpoint URL, then check connectivity from the test runner to the Router.
New session waits or times out No slot matches the requested capabilities, all matching slots are occupied, or Nodes are unavailable. Compare requested capabilities with Node slot stereotypes; check Node health and maximum-session capacity, then allow enough queue time for your workload.
Session command reaches the wrong place or fails after startup Grid state changed or the session was lost; client code may also be using a stale session. Use the session ID returned by the active driver, inspect Grid state and Node logs, and create a new session if the old one ended.
Unexpected browser or driver version Automated management selected an available version, or the environment differs from the expected machine. For reproducibility, pin and provision browser and driver versions using the documented manual configuration path.
Cannot connect to a remote endpoint from another host The endpoint is bound to loopback or network policy blocks the connection. Configure an intentional, restricted network path; do not solve this by exposing the endpoint to an unrestricted network.
BiDi subscription yields no events The selected browser or binding may not support the requested event or capability in its current version. Check current Selenium binding and browser support for that exact BiDi feature before relying on it.

10. Performance, reliability, and cost considerations

There are no benchmark figures established here, and Selenium performance depends on the browser, page, test, network, and Grid deployment. For practical planning, separate time spent creating sessions from time spent executing page actions, and monitor queue delay, Node availability, browser startup failures, and test duration. More Nodes or slots may increase available parallelism, but capacity is bounded by Node resources and configured session limits.

  • Reduce setup variability: use a consistent browser environment and record the browser and capabilities used by a run.
  • Keep sessions bounded: always quit drivers, especially in shared Grid environments, so abandoned sessions do not consume slots.
  • Plan for failure: a Grid request may wait when capacity is occupied, and remote execution introduces network and service failure points that local runs do not have.
  • Measure your own workload: use queue time, session creation time, and action timing from your deployment rather than assuming a universal throughput figure.
  • Budget operational resources: Grid requires machines or containers, browser images, maintenance, and monitoring. Selenium itself does not establish one universal infrastructure cost.

11. Screenshot capture without operating WebDriver

If your task is to produce page screenshots rather than interactively automate a browser, ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. Its one-call API accepts a URL and returns a PNG, JPEG, WebP, or PDF. See ScreenshotNeo and the API documentation.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python

import requests

r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

For error handling, check the HTTP status and response headers before treating a response body as an image. Keep the API key private, set a reasonable client timeout, and consult the documentation for available formats and parameters.

Or skip the browser setup

With ScreenshotNeo, cookie banners, popups, and chat widgets are removed before the shot. Bot checks, blank pages, and failed loads are never billed; MCP tools let AI agents take screenshots; and 1,000 screenshots a month are free with no card, with paid plans starting at $5 for 3,000. Its response headers report the page verdict and billing status.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Sign up for 1,000 free screenshots per month, with no card required.

12. Frequently asked questions

Is Selenium 4 based on the JSON Wire Protocol?

Ordinary Selenium 4 WebDriver command traffic uses the W3C WebDriver protocol. Avoid describing the architecture as only JSON Wire Protocol.

Do I need to install ChromeDriver separately?

Often not for a standard supported setup: Selenium Manager automates much of browser and driver management. Offline, locked-down, pinned, or customized environments may still need explicit configuration.

Does every Selenium test require Grid?

No. A local WebDriver session can control a browser on the test machine. Use Grid when remote allocation, multiple machines, or broader platform coverage is needed.

Does BiDi replace WebDriver commands?

No. BiDi adds a bidirectional event channel; classic WebDriver commands remain request/response operations.

Can any browser run every BiDi feature?

Do not assume identical feature coverage. Check the current browser and binding support for each event or command you depend on.

Primary references