python system_error ai_generated true

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

ID: python/pytest-selenium-webdriver-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-04-17First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.x active

Root Cause

Selenium cannot find the ChromeDriver executable. This occurs when ChromeDriver is not installed, not in PATH, or the version does not match the installed Chrome browser.

generic

中文

Selenium 无法找到 ChromeDriver 可执行文件。这发生在 ChromeDriver 未安装、不在 PATH 中,或版本与已安装的 Chrome 浏览器不匹配时。

Workarounds

  1. 95% success
    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager
    from selenium.webdriver.chrome.service import Service
    
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
  2. 92% success
    from selenium import webdriver
    
    driver = webdriver.Chrome()  # Auto-downloads driver

Dead Ends

Common approaches that don't work:

  1. 80% fail

    This makes tests non-portable and breaks on other machines or CI environments with different paths.

  2. 70% fail

    This works locally but is not reproducible. The driver may be outdated or incompatible with the browser version.