New Features in Selenium 4: What Changed and What to Adopt
Selenium 4 brings W3C WebDriver alignment, relative locators, Selenium Manager, Grid updates, and evolving WebDriver BiDi support. Learn what each feature does and how to adopt it safely.
Selenium 4 is a major update to Selenium’s browser automation stack, with five feature areas developers should understand: W3C WebDriver alignment, relative locators, Selenium Manager, a modernized Selenium Grid, and WebDriver BiDi. The practical value depends on your language binding, Selenium minor version, browser, and environment. You do not need to rewrite a working suite just because Selenium 4 has new capabilities; adopt the ones that solve a concrete setup, locator, execution, or browser event problem.
This guide uses Python for runnable examples. Its sample covers Selenium Manager, explicit waits, and a relative locator. BiDi and some manager capabilities vary by release and binding, so check the exact documentation for the version you pin.
What are the new features in Selenium 4?
| Feature | What changed | When it helps | Main caveat |
|---|---|---|---|
| W3C WebDriver alignment | Selenium’s WebDriver implementation aligns with the W3C standard. | Standards-based client and browser interoperability. | Standards alignment does not erase browser-specific behavior. |
| Relative locators | Locate an element by its position relative to a known element. | The target lacks a good direct locator, but its spatial relationship is meaningful. | Layout changes can invalidate spatial assumptions. |
| Selenium Manager | Resolves and caches a compatible driver when the binding cannot find one. | Local development and straightforward CI setup. | Automatic setup needs metadata/download access and may be affected by proxies or OS dependencies. |
| Selenium Grid 4 | Modernized remote WebDriver execution across machines and environments. | Parallel runs and broader browser or OS coverage. | Grid deployment, capacity, and debugging require operational work. |
| WebDriver BiDi | A bidirectional channel for commands and browser events is developing across Selenium bindings. | Use cases needing browser events and capabilities beyond request/response WebDriver flows. | Verify command support in the exact language binding and release. |
The Selenium 4 launch framed the release around standards alignment and updates across Selenium’s tools. Treat the feature set as a family of changes rather than a single uniform bundle: functionality arrives across versions and bindings. [Selenium 4 announcement](https://www.selenium.dev/blog/2021/announcing-selenium-4/)
Set up Selenium 4 in Python
Install Selenium in a virtual environment and save this example as selenium4_example.py. It opens a public test page, reads a heading, finds the input below that heading using a relative locator, and closes the browser even if a step fails.
python -m venv .venv
# macOS/Linux:
source .venv/bin/activate
# Windows PowerShell:
# .venv\Scripts\Activate.ps1
python -m pip install --upgrade selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.relative_locator import locate_with
from selenium.webdriver.support.ui import WebDriverWait
options = webdriver.ChromeOptions()
# Uncomment to run without opening a visible browser window:
# options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://www.selenium.dev/selenium/web/web-form.html")
wait = WebDriverWait(driver, 10)
heading = wait.until(EC.visibility_of_element_located((By.TAG_NAME, "h1")))
text_input = wait.until(
EC.visibility_of_element_located(
locate_with(By.TAG_NAME, "input").below(heading)
)
)
text_input.send_keys("Selenium 4")
print("Heading:", heading.text)
print("Input value:", text_input.get_attribute("value"))
finally:
driver.quit()
With Selenium 4.6 or later, the Python binding can use Selenium Manager when no driver path is supplied. It attempts to discover the installed browser version, resolve a compatible driver using vendor metadata, download it, and cache it. The browser must already be installed for this driver-management flow. Manager’s browser-management features arrived later: Chrome from 4.11, Firefox from 4.12, and Edge from 4.14. [Selenium Manager documentation](https://www.selenium.dev/documentation/selenium_manager/)
Setup alternatives and configuration
- Use Selenium Manager: the simplest local setup is
webdriver.Chrome()or the corresponding browser constructor without an explicit driver path. - Provide a driver explicitly: in locked-down or reproducible environments, provision the browser and matching driver yourself and configure the driver service path for your binding.
- Use a remote browser: create a remote WebDriver session against a Grid URL when the browser runs elsewhere. Capabilities and options must match the remote nodes available in that Grid.
- Pin versions in CI: pin Selenium and control browser/driver images or versions so a new browser release does not unexpectedly change the environment.
- Use waits deliberately: prefer explicit waits for the state a test needs. Fixed sleeps add idle time and still may be too short under load.
W3C WebDriver alignment
Selenium 4 aligns its WebDriver implementation with the W3C WebDriver standard. This gives clients and browsers a standards-based protocol foundation. It does not guarantee identical rendering, timing, browser extensions, permissions, or vendor-specific behavior across browsers and operating systems. Keep cross-browser assertions focused on behavior your product promises, and run coverage against the browser versions your users need.
For teams moving from older Selenium versions, check the Selenium 4 migration notes and your binding’s changelog for API removals or changed behavior rather than assuming all old code must be replaced. The release announcement is useful context, but the language-specific API documentation should guide the actual migration.
What are relative locators in Selenium 4?
Relative locators select an element by its position relative to a known reference element. Selenium supports relationships such as above, below, to_left_of, to_right_of, and near. The reference is still located through a conventional locator.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with
label = driver.find_element(By.XPATH, "//label[normalize-space()='Email']")
email_input = driver.find_element(
locate_with(By.TAG_NAME, "input").to_right_of(label)
)
Relative location is useful when a target has no stable ID, name, or distinctive accessible attribute, while its relationship to a reliable label or heading is part of the page design. Selenium’s locator documentation describes the locator strategies and binding APIs. [Locator strategies](https://www.selenium.dev/documentation/webdriver/elements/locators/)
When to use them—and when not to
- Use a direct ID, name, accessible label, or stable CSS selector when one exists; it usually expresses the target’s identity more directly.
- Use a relative locator when the spatial relationship itself is meaningful and stable, such as an input beside its label.
- Avoid depending on “the button below this text” when responsive layouts, localization, content changes, or CSS rearrangement could move the elements.
- If multiple elements satisfy the relationship, narrow the search with a stronger reference or a more specific locator and assert the result.
What is Selenium Manager?
Selenium Manager is the official driver manager shipped with Selenium releases. When a binding cannot find a driver, it can discover the installed browser, resolve a matching driver, download it, and cache it locally. You can still supply drivers yourself. This reduces routine manual setup, but it is not a guarantee that a fresh machine can start a browser without network access or system dependencies.
Version milestones matter: driver management is available beginning with Selenium 4.6; documented browser management arrived for Chrome in 4.11, Firefox in 4.12, and Edge in 4.14. Check the official manager documentation for supported configuration, cache behavior, and current environment requirements.
Manager constraints to plan for
- First-time resolution needs access to browser vendor metadata and downloads; a corporate proxy or firewall can block it.
- Some Linux browser builds require OS libraries that Selenium Manager does not install.
- Windows Edge browser download behavior differs because its installer requires administrator rights.
- For offline or tightly controlled builds, install the browser and driver through your normal image or package process, then configure Selenium to use that driver.
What is new in Selenium Grid 4?
Grid runs WebDriver sessions remotely across machines. It lets teams run tests against different browser and operating system environments and distribute session execution. Grid 4 modernized this infrastructure; it does not make every suite faster automatically. Throughput depends on test duration, available browser slots, machine capacity, network overhead, and how well the suite can run independently.
A minimal Python remote-session pattern looks like this, assuming a Grid is already running and reachable at the configured URL:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.set_capability("browserName", "chrome")
driver = webdriver.Remote(
command_executor="http://localhost:4444",
options=options,
)
try:
driver.get("https://example.com")
print(driver.title)
finally:
driver.quit()
Replace the example endpoint with your Grid endpoint, and request only capabilities supported by its nodes. The Grid documentation covers architecture, setup, and operational modes. [Selenium Grid documentation](https://www.selenium.dev/documentation/grid/)
Grid adoption checklist
- Decide which browser and OS combinations require remote coverage.
- Provision enough session capacity for the intended parallel workload.
- Make test data and test setup independent so parallel sessions do not collide.
- Capture session logs and artifacts where your Grid deployment supports them.
- Measure queue time and total suite time in your own environment before expanding concurrency.
What is WebDriver BiDi?
WebDriver BiDi is a bidirectional communication channel between an automation client and browser. Classic WebDriver is primarily a command/response model; BiDi adds a foundation for browser events and commands over an ongoing connection. Selenium’s support is evolving, with work continuing across language bindings, schemas, and commands.
Do not add BiDi as a general dependency based only on the Selenium major version. Before adopting a command, confirm that it is implemented by the exact Selenium release and language binding you use, and that the target browser supports the needed behavior. Selenium 4.49’s release notes show continuing BiDi development, so consult the current release and binding API references before implementation. [Selenium 4.49 release notes](https://www.selenium.dev/blog/2026/selenium-4-49-released/)
How should a team adopt Selenium 4 features?
- Upgrade the binding in a branch. Pin the selected Selenium version and run the existing suite against the browsers used in development and CI.
- Remove unnecessary driver downloads carefully. Try Selenium Manager on developer machines first; confirm network and proxy policy before relying on it in CI.
- Improve locators selectively. Prefer stable direct attributes; use relative locators only for relationships that remain true across responsive layouts and content changes.
- Use Grid for a clear coverage or throughput need. Start with one remote browser configuration and measure capacity, queueing, and failure diagnosis.
- Evaluate BiDi against a specific requirement. Verify the specific command and binding availability at the version you intend to ship.
- Keep an upgrade record. Record Selenium, browser, driver, OS image, and Grid versions so failures can be reproduced.
Performance, reliability, and cost considerations
- Test speed: Relative locators do not inherently make a suite faster. Grid can increase concurrency if there is available capacity and tests can run independently; queueing and remote startup can offset gains.
- Reliability: Selenium Manager removes one source of manual mismatch, but adds a dependency on metadata/download access when resolving a driver. Pinning browser and driver inputs is often preferable for repeatable CI.
- Locator maintenance: Spatial locators can make a test readable where relationships are stable, but layout changes can break them. Stable semantic attributes remain a strong default.
- Infrastructure cost: Selenium itself does not determine the cost of your Grid machines, browser infrastructure, or CI minutes. Estimate capacity using your own workload and concurrency targets; no universal performance or cost figure applies.
- BiDi readiness: Treat support as a versioned capability, not a promise that every binding has the same commands.
Troubleshooting Selenium 4
| Symptom | Likely cause | What to do |
|---|---|---|
| Driver resolution fails on first run | Proxy, firewall, DNS, or vendor metadata/download access blocks Selenium Manager. | Check network access and proxy configuration. In restricted environments, provision a compatible driver explicitly. |
| Browser starts locally but not on Linux CI | The browser build needs OS libraries missing from the image. | Install the required system dependencies in the image or use an environment with those libraries available. |
| Edge browser management behaves differently on Windows | Browser installer permissions differ; installation may require administrator rights. | Install Edge through an approved machine image or package process, then let Selenium resolve its driver or provide the driver path. |
NoSuchElementException for a relative locator |
The reference was found but the expected spatial relationship does not hold at lookup time, or the page has shifted. | Wait for both relevant elements, inspect the rendered layout, and prefer a stable direct locator if available. |
| Relative locator selects the wrong matching element | Several elements satisfy the same spatial relation. | Use a more specific reference, narrow the candidate set, or select by a stable semantic attribute. |
| BiDi example or method is missing | The command is not implemented in that binding or Selenium release. | Check the binding API docs and release notes; upgrade only if the required feature is supported and tested for your browser. |
| Grid session cannot be created | Grid URL is unreachable, no node matches the requested capabilities, or capacity is exhausted. | Check endpoint and network route, compare requested capabilities with node capabilities, and inspect available session capacity. |
| Remote test is slower than local | Remote startup, network delay, queueing, or resource contention outweighs parallel benefit. | Measure the full run, check Grid utilization, and increase concurrency only when capacity and test isolation permit. |
Or skip the browser setup
If your task is to capture a page rather than interact with it as part of a browser test, ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns a PNG, JPEG, WebP, or PDF. Its capture process accepts cookie and consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before the shot; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
Python one-call example (install requests first with python -m pip install requests):
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
See the ScreenshotNeo API documentation for authentication and parameters. The API also has cURL and Node.js examples, and supports full-page screenshots, element capture, device and viewport settings, PDF output, custom waits, and other capture controls.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
ScreenshotNeo provides 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000 screenshots. Sign up for the free plan.
FAQ
Do I need to rewrite my Selenium 3 tests for Selenium 4?
Not necessarily. Upgrade in a branch, run your suite against its supported browser matrix, and update only code affected by API or behavior changes.
Are relative locators always more robust than XPath or CSS?
No. They express spatial relationships, which are useful only when those relationships are stable. A reliable ID or semantic locator is usually clearer when available.
Does Selenium Manager install every browser automatically?
Its browser-management support depends on browser and Selenium version, and operating system permissions can constrain installation. Check its current documentation for your combination.
Does WebDriver BiDi replace WebDriver?
BiDi adds a bidirectional capability path. Check whether the particular events and commands you need are supported before making it part of a test design.
When should I move tests to Grid?
Use Grid when remote environments, browser coverage, or parallel execution justify the added infrastructure and operational work.


