Python Selenium脚本报错:无法连接到chromedriver服务
Selenium无法连接chromedriver服务的报错排查与解决
报错信息
File "C:\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 109, in start
raise WebDriverException(f"Can not connect to the Service {self._path}")
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:\Users\usernamehere.wdm\drivers\chromedriver\win64\123.0.6312.58\chromedriver-win32/chromedriver.exe
测试代码
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager options = Options() options.headless = False options.add_argument("--window-size=1200,576") options.add_argument("--start-maximized") service = Service(ChromeDriverManager().install()) driver = webdriver.Chrome(service=service,options=options)
解决思路
- 修正路径格式:报错路径混合了Windows不兼容的
/和\,手动指定路径时统一使用双反斜杠\\或正斜杠/,也可以将ChromeDriverManager的安装目录改为无特殊字符的路径。 - 处理权限限制:
- 将chromedriver.exe复制到权限宽松的目录(如D盘自建的
chromedriver文件夹),手动指定路径:service = Service("D:\\chromedriver\\chromedriver.exe") - 右键Python脚本选择「以管理员身份运行」,或给chromedriver所在的用户目录添加读写权限。
- 将chromedriver.exe复制到权限宽松的目录(如D盘自建的
- 验证版本匹配:通过
chrome://version/查看本地Chrome浏览器版本,确保chromedriver版本与浏览器完全一致。若ChromeDriverManager安装版本不符,手动下载对应版本替换。 - 规避Admin by Request干扰:临时关闭该工具,或将chromedriver移至不受该工具管控的目录后重新测试。
内容的提问来源于stack exchange,提问作者tom bannister
相关产品推荐
相关产品推荐

