Selenium Grid "Could not start a new session" in CI
A RemoteWebDriver request reaches the Grid hub, but the hub cannot complete a session: either the remote address is wrong, or a node accepted the slot and the browser failed to start there. The error names both possibilities.
What this error means
The test fails with "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure." pointing at the Grid endpoint.
SessionNotCreatedException: Could not start a new session.
Possible causes are invalid address of the remote server or browser start-up failure.
Host info: host: 'grid-hub', ip: '10.0.0.5'
Build info: version: '4.21.0'Common causes
The remote URL is wrong or unreachable
The RemoteWebDriver points at a hub address the runner cannot reach, or at /wd/hub on a Grid version that moved the endpoint.
A node accepted the slot but the browser crashed
The node started the browser without container-safe flags, so it crashed at startup and the session could not be created.
How to fix it
Point at the right hub URL and pass safe flags
- Use the correct Grid endpoint for your version (Selenium 4 uses the hub root, not always /wd/hub).
- Pass --no-sandbox and --disable-dev-shm-usage via browser options so the node browser starts.
- Re-run so the node creates the session.
from selenium.webdriver.chrome.options import Options
opts = Options(); opts.add_argument("--no-sandbox"); opts.add_argument("--disable-dev-shm-usage")
driver = webdriver.Remote(command_executor="http://grid-hub:4444", options=opts)Wait for the Grid to be ready
Poll the Grid status endpoint until it reports ready before sending sessions so the hub and nodes are up.
- run: |
for i in $(seq 1 30); do
curl -sf http://grid-hub:4444/status | grep -q '"ready": *true' && break || sleep 2
doneHow to prevent it
- Use the correct Grid endpoint for the Selenium version.
- Pass container-safe browser flags so node browsers start.
- Poll /status for ready before dispatching sessions.