WebDriverException: Message: unknown error: cannot find Chrome binary in Selenium
Install Google Chrome or Chromium on the operating system, or configure options.binary_location = '/path/to/chrome' explicitly in your Selenium ChromeOptions.
Root Cause Analysis
This error occurs when Python tries to initialize Selenium's webdriver.Chrome() service, but the local operating system cannot find the Google Chrome executable binary in the standard system PATH or default installation directories.
Selenium Architecture & Browser Drivers
Selenium relies on a three-tier architecture: Python Script → ChromeDriver (Service) → Google Chrome (Browser Binary). While Selenium 4+ includes an automated driver manager (Selenium Manager) to download the matching chromedriver automatically, it still requires the actual Google Chrome browser or Chromium binary to be installed on the machine.
Typical Failure Environments
- Minimal Docker Containers: Standard Linux Docker images (such as
python:3.12-slimoralpine) do not include desktop browser packages. - Headless Linux Servers & CI/CD: Running automated tests on GitHub Actions, AWS EC2, or VPS instances where Chrome was not provisioned.
- Non-Standard Installation Directories: Installing Chrome in portable directories or custom enterprise paths not indexed in the system PATH.
- Permission Restrictions: User accounts lacking execute permissions on the browser binary file.
Reproduction Code (MCVE)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import WebDriverException
# Setting an invalid binary location demonstrates the exact exception raised
options = Options()
options.binary_location = '/nonexistent/path/to/google-chrome-binary'
raise WebDriverException('Message: unknown error: cannot find Chrome binary at ' + options.binary_location)
Solution 1: Configure Explicit `binary_location` in ChromeOptions
Provide the exact absolute path to your Google Chrome or Chromium executable via Options.binary_location.
import os
import sys
from selenium.webdriver.chrome.options import Options
options = Options()
# Common default binary locations by operating system
if sys.platform.startswith('win'):
default_path = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
elif sys.platform.startswith('darwin'):
default_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
else:
default_path = '/usr/bin/google-chrome'
if os.path.exists(default_path):
options.binary_location = default_path
print(f'Configured Chrome binary location: {options.binary_location}')
else:
print('Chrome not found in default path — install google-chrome-stable or set custom path.')
Solution 2: Provision Headless Chromium in Docker & CI/CD Pipelines
In Linux/Docker environments, install Chromium and run in headless mode with sandboxing disabled.
from selenium.webdriver.chrome.options import Options
def get_headless_chrome_options() -> Options:
options = Options()
options.add_argument('--headless=new')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
return options
opts = get_headless_chrome_options()
print(f'Prepared headless Chrome arguments: {opts.arguments}')
Note de reproductibilité
La reproductibilité de cette erreur dépend directement de la configuration du système d'exploitation hôte (Linux, macOS, Windows) et de la présence effective du navigateur Google Chrome ou Chromium sur la machine.
Edge Cases & Docker Container Recommendations
When running in Docker containers, do not attempt to install desktop Google Chrome via GUI packages. Instead, add the official Chromium repository:
apt-get update && apt-get install -y chromium chromium-driver
Contrasting WebDriverException: cannot find Chrome binary with SessionNotCreatedException: This version of ChromeDriver only supports Chrome version X: The binary error means the browser does not exist at all, while the session error means both browser and driver exist but their major version numbers (e.g. 120 vs 122) are incompatible.