Glossary
Selenium Grid: spreading browser sessions over many machines
Selenium Grid accepts WebDriver sessions at one address and hands each one to a machine that has the requested browser free, so many sessions run side by side.
The problem it solves
One machine can run a limited number of browsers before memory and CPU run out. A test suite with two thousand cases, or a data job that needs a browser for every page, quickly outgrows a single host. Grid lets your scripts keep pointing at one URL while the actual browsers live on many nodes. Your code changes from webdriver.Chrome() to a remote driver with the Grid address, and nothing else.
How the pieces fit
Since Selenium 4, Grid is split into roles that can run together in one process (standalone mode) or separately for large setups.
- Router: the entry point that receives every request.
- Distributor: picks a node that matches the requested capabilities.
- Session map: remembers which session lives on which node.
- Session queue: holds new session requests while all slots are busy.
- Nodes: the machines or containers that actually run browsers, each with a number of slots.
- Event bus: carries messages between the parts.
For a small team, standalone or "hub and node" mode is enough. The fully distributed mode suits large, long running installations.
Requesting a browser
from selenium.webdriver import ChromeOptions, Remote
opts = ChromeOptions()
opts.add_argument("--window-size=1366,900")
remote = Remote(
command_executor="http://grid.internal:4444",
options=opts,
)
try:
remote.get("https://example.com/status")
print(remote.title)
finally:
remote.quit() # frees the slot for the next session
The options object carries capabilities such as browser name, version and platform, and the distributor matches them against what the nodes offer.
Running nodes in containers
The Selenium project publishes container images for the hub and for Chrome, Firefox and Edge nodes. Starting nodes as containers makes scaling a matter of raising the replica count, and setups for Kubernetes can add nodes automatically when the session queue grows. See containerized scraping for memory and shared memory settings that apply here too.
Timeouts and cleanup
Grid closes sessions that sit idle beyond a timeout, which protects slots from scripts that crashed without calling quit. Set it long enough for your slowest legitimate step. A step that waits for an external answer, such as a CAPTCHA solve, counts as idle from Grid's point of view if the browser receives no commands. Token tasks usually come back within seconds (under 9 seconds for reCAPTCHA v2), and GateSolver gives up after 120 seconds and marks the task failed at no charge, so an idle timeout of a few minutes covers the worst case.
Parallel solving with a grid
A grid running fifty sessions may meet fifty challenges at once. That is fine for the solving side: there is no cap on concurrent tasks. What you share is the 600 requests per minute per key budget, which covers creates and polls together, so poll every three seconds rather than every half second. If many sessions share one account, a small helper service that polls all open tasks in one loop keeps the request count low (see concurrency). For the basics of driving a single browser, start with Selenium and the Selenium integration guide.
Common questions
What is the difference between Selenium and Selenium Grid?
Selenium WebDriver drives one browser from your code. Grid routes many such sessions to a pool of remote machines.
Do I need to change my tests to use Grid?
Only the driver creation: you use a remote driver pointed at the Grid URL with the same options.
What happens when all Grid slots are busy?
New session requests wait in the session queue until a slot frees up or the request times out.
Why did Grid close my session in the middle of a run?
The session was idle longer than the configured timeout, for example while waiting on an outside step.
Can Grid nodes run in Docker?
Yes. Official images exist for the hub and for Chrome, Firefox and Edge nodes.
Keep reading
- SeleniumThe long standing browser automation project built on WebDriver, usable from many languages and scalable through Grid.
- SeleniumThe reference Selenium setup in Python and Java: explicit waits, reCAPTCHA v2 and Turnstile tokens, callbacks, retries and Grid scaling.
- Containerized scrapingPackaging scrapers and their browsers into containers so the same worker runs anywhere and scales out by adding copies.
- ConcurrencyRunning many requests or solving tasks at the same time, and how per host limits and backpressure keep it under control.