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

Python使用Selenium连接已启动Chrome浏览器时卡住如何解决?

Selenium连接已启动Chrome实例卡住解决方案

可能原因及对应排查步骤

  • Chrome与ChromeDriver版本不匹配

Chrome默认开启后台自动更新,若此前流程可正常运行,大概率是Chrome自动升级后和你本地的chromedriver.exe版本不兼容。你可以打开Chrome地址栏输入chrome://version/查看当前浏览器版本,再下载对应版本的ChromeDriver替换本地文件即可。

  • 远程调试端口未正常绑定

先在CMD执行以下命令检查9878端口是否被Chrome进程正常占用:
netstat -ano | findstr "9878"
如果无返回结果,说明你启动带调试端口的Chrome失败,可以先任务管理器结束所有Chrome进程,再重新执行启动命令:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9878

  • Selenium版本升级导致传参方式失效

如果你近期升级过Selenium到4.6及以上版本,旧版直接传入驱动路径的写法已经废弃,会导致卡住或报错,需要调整写法。

  • 本地代理/防火墙拦截

检查是否开启了全局代理,或系统防火墙拦截了本地127.0.0.1的9878端口请求,可临时关闭代理和防火墙测试。

修正后适配Selenium 4.x的代码

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9878")
# 适配高版本Selenium的传参方式,用Service类封装驱动路径
chrome_service = Service(executable_path="chromedriver.exe")
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
driver.get("https://www.google.com/")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 09:24:01