# selenium.common.exceptions.WebDriverException: 消息: 'chromedriver' 可执行文件需要在 PATH 中。

- **ID:** `python/pytest-selenium-webdriver-exception`
- **领域:** python
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (98% 成功率)
   ```
   pip install webdriver-manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
   ```
2. **** (90% 成功率)
   ```
   driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
   ```
3. **** (95% 成功率)
   ```
   Check Chrome version: chrome://version/
Download matching ChromeDriver from https://chromedriver.chromium.org/
   ```

## 无效尝试

- **** — If the version is incompatible with Chrome, Selenium will still fail with a different error. (70% 失败率)
- **** — This relies on PATH and may fail if chromedriver is not installed system-wide. (80% 失败率)
- **** — Does not solve the missing driver issue and may introduce other incompatibilities. (90% 失败率)
