selenium WebDriverException: cannot find XXXXX binary

it2025-08-30  27

原因

selenium执行时,找不到需要的exe文件

1.浏览器exe,比如 Chrome.exe 2. webdriver的exe,比如 chromedriver.exe

解决方法

修改 PATH 环境变量:

将浏览器,比如Chrome就是"chrome.exe"的路径添加到PATH将webdriver的路径添加到 PATH 或者 直接将webdriver的执行文件放到浏览器目录里

为什么不用这种方法?

options = webdriver.ChromeOptions() options.binary_location = r"D:\Software\Chrome\Application\chrome.exe" browser = webdriver.Chrome(chrome_options=options)

代码写死了路径,代码和环境产生了纠缠,也就是常说的耦合(coupling).

备忘

先看懂错误描述 定个安装规范

浏览器、webdriver执行文件目录添加到path

最新回复(0)