You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium连接Chrome Web Driver失败问题求助

无法连接Chrome Web Driver的问题及求助

我一直尝试通过Selenium访问Google Chrome,但始终无法连接Chrome Web Driver。最初收到Chrome版本不兼容的错误提示,于是我下载了最新版本的驱动,但问题仍未解决。

尝试的方法及报错

方法1:直接初始化Chrome驱动

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select


driver=webdriver.Chrome()

报错信息:

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 117.0.5938.150 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe

方法2:使用ChromeDriverManager安装驱动

driver=webdriver.Chrome(service=Service(ChromeDriverManager().install()))

报错信息:

ConnectionError: Could not reach host. Are you offline?

方法3:直接传入ChromeDriverManager安装路径

driver=webdriver.Chrome(ChromeDriverManager().install())

报错信息:

ConnectionError: Could not reach host. Are you offline?

方法4:直接传入ChromeDriverManager对象

driver=webdriver.Chrome(ChromeDriverManager())

报错信息:

NoSuchDriverException: Message: Unable to obtain chromedriver using Selenium Manager; 'ChromeDriverManager' object has no attribute 'capabilities'; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

解决方案

1. 手动匹配Chrome版本下载对应驱动

  • 查看Chrome版本(地址栏输入chrome://version/),对应下载同大版本号的ChromeDriver
  • 解压后将chromedriver.exe放在Chrome安装目录(C:\Program Files\Google\Chrome\Application\),或添加到系统环境变量PATH中
  • 代码中指定驱动路径:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path="C:/Program Files/Google/Chrome/Application/chromedriver.exe")
driver = webdriver.Chrome(service=service)

2. 解决ChromeDriverManager网络问题

若使用ChromeDriverManager时出现ConnectionError,可通过以下方式处理:

  • 检查网络连接,确认能正常访问外网
  • 设置国内镜像源:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager(url="https://npm.taobao.org/mirrors/chromedriver/").install()))

3. 升级Selenium并使用内置管理器

确保Selenium为最新版本,执行pip install --upgrade selenium升级后,新版本内置的Selenium Manager可自动匹配驱动:

from selenium import webdriver

driver = webdriver.Chrome()

若仍报错,大概率是网络问题导致管理器无法下载驱动,回到手动配置驱动路径的方案即可。

内容的提问来源于stack exchange,提问作者Jeff Gordon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 19:12:48