Selenium Manager, browser options and RemoteWebDriver
Selenium Manager, built into Selenium since version 4.6, picks and downloads the driver for the installed browser on its own. It needs a network on the first run, so in a closed CI the cache is prepared or the driver path is given. Browser options go through ChromeOptions and its counterparts, and RemoteWebDriver connects by URL to a Grid or cloud. In headless mode the window size is set.
Selenium · Driver and options
The test is green locally, but on a clean CI agent the session is not created. What differs?
A test that passed on a laptop an hour ago fails on a new CI agent with SessionNotCreatedException: the driver is not found or its version does not fit the browser. This used to be a daily pain: Chrome updated while chromedriver stayed old. Now Selenium Manager does most of this work, but it has limits worth knowing before running tests in a closed network or on a Docker image. The lesson covers what Selenium Manager does on its own, how to pass settings to the browser and how RemoteWebDriver differs from a local driver.
How it works and why. Selenium Manager is built into Selenium since version 4.6: a small executable the library calls when you create a driver without an explicit path. It finds out which browser is installed and its version, picks the matching driver, downloads it and puts it in a cache (by default ~/.cache/selenium). Unused versions are removed from the cache after 30 days. From version 4.11 for Chrome (4.12 for Firefox, 4.14 for Edge) it can also download the browser itself when it is missing: Chrome comes from Chrome for Testing. For Edge on Windows, installing the browser needs administrator rights.
This changes the typical test code:
// the outdated approach: the driver path by hand
System.setProperty("webdriver.chrome.driver",
"C:/tools/chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriver driver = new ChromeDriver();
Selenium Manager takes its settings in this priority order: command-line arguments, then the se-config.toml file in the cache root, then environment variables with the SE_ prefix. The cache path (SE_CACHE_PATH), offline mode (SE_OFFLINE), TTL and mirrors cannot be set through browser options, only through variables or the file. You can also point to your own browser (SE_BROWSER_PATH) or a specific driver version (SE_DRIVER_VERSION).
Driver preparation: before and now
By hand
Download chromedriver for the Chrome version, put it in the repo or image, set the path. The browser updated: tests fail.
Selenium Manager
new ChromeDriver() finds the browser, picks and caches the driver. A network is needed on the first run.
Example: options for CI. Browser options are passed through separate classes: ChromeOptions, FirefoxOptions, EdgeOptions. DesiredCapabilities as the main way is a leftover of Selenium 3.
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new", "--window-size=1920,1080");
options.setPageLoadStrategy(PageLoadStrategy.EAGER);
options.setAcceptInsecureCerts(true); // test environments only
WebDriver driver = new ChromeDriver(options);
The window size is set deliberately: in headless mode the default window is small, and responsive layout switches to its mobile view, so elements appear and disappear differently from the local machine. pageLoadStrategy controls what driver.get() waits for: normal waits for the full page load, eager only for DOMContentLoaded, none does not wait at all. eager speeds up tests on pages with heavy third-party scripts, but then the test itself must wait for the elements it needs. acceptInsecureCerts allows self-signed certificates of a test environment: do not do this against production.
RemoteWebDriver connects by URL to a remote node: Selenium Grid, a Docker container or a cloud platform. The options are the same, only the way of creation changes:
ChromeOptions options = new ChromeOptions();
URL gridUrl = URI.create("http://localhost:4444").toURL();
WebDriver driver = new RemoteWebDriver(gridUrl, options);
The rest of the test stays unchanged: this is the point of the common WebDriver interface. But now the driver runs on another machine, so file paths, downloads and screenshots need separate care (Grid and threads are covered in the lessons “Selenium Grid 4 and Docker: how it is built and how to run it” and “Parallel runs: a driver per thread, isolation, CI”).
Limits and alternatives. Selenium Manager needs a network on the first run: the driver and browser are downloaded from external sources. In a closed network, in a bank or in a container with no internet access it is switched to offline mode and the cache is prepared beforehand: warm up the image, mount the cache or point explicitly to the driver. What exactly happens with SE_OFFLINE=true when the needed driver is not in the cache is not specified in the documentation, so it is safer to check it on your own image. In such an environment:
# on CI without a network: a cache prepared beforehand
export SE_CACHE_PATH=/opt/selenium-cache
export SE_OFFLINE=true
mvn test
Third-party libraries such as WebDriverManager are no longer needed in a new project: the built-in manager does their job. When full reproducibility is needed (the same browser version for everyone), use a pinned Docker image with the browser or Grid, not "the latest Chrome on the agent".
Common mistakes.
- Leaving
System.setProperty("webdriver.chrome.driver", ...)with a hard-coded path: the test works only on the author's machine and uses a stale driver on CI. - Running headless without a window size: responsive layout switches, and locators that worked on desktop find no elements.
- Relying on the manager to download the browser in a closed network: the first run hangs or fails.
- Enabling
eagerornonewithout explicit waits: the test starts looking for elements before the load ends and becomes flaky.
Check yourself
A team removed System.setProperty and WebDriverManager, and on a CI with no internet the tests stopped starting. What was wrong with the migration?
Answer
Selenium Manager downloads the driver (and the browser if needed) on the first run, so it needs a network. Without one, you must prepare the cache beforehand (SE_CACHE_PATH, an image with a warmed cache) or point to the driver explicitly and turn on offline mode.
Why does a test on a page with a responsive menu fail in headless mode but pass in a regular window?
Answer
The default headless window is smaller than a desktop one, so the page shows its mobile layout: the menu is collapsed into a "burger" and the expected elements are hidden. The fix: set the size explicitly (--window-size=1920,1080) in the options.
new ChromeDriver() is enough. I pass browser settings through ChromeOptions and connect to a remote node through RemoteWebDriver by URL. Middle/Senior: I know the manager needs a network on the first run, so for closed CI I prepare the cache (SE_CACHE_PATH, SE_OFFLINE) or use a pinned image with the browser. I pin the browser version for reproducibility through an image or Grid, and in headless I always set the window size and choose pageLoadStrategy together with explicit waits.