2025, Nov 15 03:00

How to Fix Selenium SessionNotCreatedException Caused by ChromeDriver–Chrome Version Mismatch under Enterprise Constraints

Resolve Selenium SessionNotCreatedException by matching ChromeDriver with Chrome 137. Drop undetected_chromedriver, set browser_version, run enterprise tests.

When you are locked to a specific Chrome build by enterprise policy, a routine Selenium setup can suddenly fail with a loud SessionNotCreatedException. A common trigger is a mismatch between the installed Chrome version and the ChromeDriver that Selenium attempts to use. If Chrome 137 is all you have, but the driver targets 138, the session will never start.

Problem: version mismatch under enterprise constraints

The setup below tries to drive the browser with undetected_chromedriver and a minimal ChromeOptions configuration. On a machine where Chrome is pinned to 137, Selenium ends up reporting that it can only talk to Chrome 138, and quits with SessionNotCreatedException.

from selenium import webdriver
import undetected_chromedriver as stealth
import time
from selenium.webdriver.common.by import By
import urllib
opts = webdriver.ChromeOptions()
opts.add_argument("--disable-extensions")
client = stealth.Chrome(options=opts)
client.get('https://www....')

The error explicitly states that the ChromeDriver in use supports only Chrome 138, while the installed browser is 137. Because the driver cannot attach to a different major version, the session never initializes.

Why this happens

ChromeDriver must match the major version of Chrome. If the driver is for 138 and the browser is 137, Chrome refuses the connection and Selenium surfaces SessionNotCreatedException. Adding flags or retrying does not change that fundamental requirement. Another detail that surfaced in practice is that passing the browser version incorrectly can cause InvalidArgumentException; the version must be provided as a string.

There is also an extra source of friction here. The regular Selenium flow works fine once the correct driver is selected. The additional layer introduced by undetected_chromedriver is not helping in this scenario, and it has been called outdated and unmaintained. Removing it avoids the extra moving parts and aligns with the working configuration.

Solution: pin the browser version and use the stock Selenium driver

If Chrome 137 is installed and available on your PATH, set the browser_version property before creating the driver and switch to the regular Selenium Chrome driver. This prompts the tooling to fetch the compatible ChromeDriver 137 and launch your locally installed Chrome 137. Make sure to pass the version as a string.

from selenium import webdriver
cfg = webdriver.ChromeOptions()
cfg.browser_version = "137"
cfg.add_argument("--disable-extensions")
driver = webdriver.Chrome(options=cfg)
driver.get("https://www....")

This configuration uses the appropriate ChromeDriver 137 and starts a session against Chrome 137 without the version conflict.

Why it matters

Keeping Chrome and ChromeDriver on the same major version is not just a best practice; it is a hard requirement for establishing a session. In environments where upgrading Chrome is not an option, explicitly pinning the driver to the installed browser version prevents brittle setups and unblocks test or automation runs. It also avoids chasing unrelated flags or workarounds that cannot solve a driver–browser incompatibility.

It is worth noting that removing undetected_chromedriver allowed the target page to load in this case. If a site denies access because automation is detected, that is a separate challenge. The fix above addresses only the version mismatch and session creation; it does not change site detection behavior.

Takeaways

If you are constrained to Chrome 137, declare that version up front and use the standard Selenium Chrome driver. Provide the version as a string, keep your options minimal, and let the tooling fetch the matching ChromeDriver. This keeps the stack aligned, avoids SessionNotCreatedException, and reduces friction from unmaintained layers that do not contribute to resolving version conflicts.