FAQ Selenium中提示can not connect to the service chromedriver 的解决方法
can not connect to the service chromedriver问题的处理
背景
一个同学反馈运行如下代码
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get("https://cn.bing.com")
driver.find_element("id","sb_form_q").send_keys("松勤软件测试\n")
sleep(3)
driver.quit()报错了

一看这个错误没见到过,驱动应该是有的,版本也应该对的,无法连接到chromedriver
考虑到chromedriver本身就是一个web server
C:\Users\songqin008>chromedriver
Starting ChromeDriver 103.0.5060.134 (8ec6fce403b3feb0869b0732eda8bd95011d333c-refs/branch-heads/5060@{#1262}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
其实你是可以在浏览器中访问http://127.0.0.1:9515/的,当然这个get并不会返回太多有用的信息,只能说可以看到。
解决
一开始我只想到这里,但不知道如何解决
搜索引擎一查,说是hosts文件可能会影响
查了下这位同学的hosts
少了下面一行
127.0.0.1 localhost
加上后解决
思考
猜猜:代码自动调起chromedriver,并作为webserver访问其api,这个地址可能是127.0.0.1?但没有找到所以报错。
搜索代码发现,报错信息在selenium\webdriver\common\service.py,105行
while True:
self.assert_process_still_running()
if self.is_connectable():
break
count += 1
sleep(0.5)
if count == 60:
raise WebDriverException("Can not connect to the Service %s" % self.path)
30秒超时时间会提示这个,跟实际代码运行效果类似。
那代码self.is_connectable()就应该是不为True的
def is_connectable(self):
return utils.is_connectable(self.port)再看is的定义
def is_connectable(port: int, host: Optional[str] = "localhost") -> bool:
pass #略答案呼之欲出,上面的代码默认值就是localhost
你现在没有这个,自然就不行咯
FAQ Selenium中提示can not connect to the service chromedriver 的解决方法的更多相关文章
- selenium WebDriver提示Unable to find a matching set of capabilities解决方法
问题出在:应该将火狐浏览器驱动添加到火狐浏览器安装目录下,并且将火狐浏览器安装目录放在path下面.(出现大意,忘了在火狐浏览器下放其对应的驱动) 亲测以下组合方式可用: pycharm-comm ...
- rpm包安装过程中依赖问题“libc.so.6 is needed by XXX”解决方法
rpm包安装过程中依赖问题"libc.so.6 is needed by XXX"解决方法 折腾了几天,终于搞定了CentOS上的Canon LBP2900打印机驱动.中间遇到了一 ...
- PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法
这篇文章主要介绍了PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,是在进行PHP数据库程序开发中常会遇 ...
- Win10无法连接远程桌面提示“你的凭据不工作”的三个解决方法
Win10无法连接远程桌面提示"你的凭据不工作"的三个解决方法(转藏) 解决方法一:修改组策略 1.在"开始"窗口运行gpedit.msc,进入计算机配置-&g ...
- win10提示“无法设置移动热点 请打开WLAN”的解决方法
一位用户在使用Win10创意者操作系统过程中,遇到了无法开启移动热点的情况,开关呈灰色状态,而且提示:无法设置移动热点 请打开WLAN,该如何解决呢?该用户表示Wlan一直开着呀,感觉非常奇怪.接下来 ...
- 使用sklearn中的fetch_mldata的错误情况以及可能可行的解决方法
使用sklearn中的fetch_mldata的错误情况以及可能可行的解决方法 在notebook使用的时候出现了报错 from sklearn.datasets import fetch_mldat ...
- 使用VMware Converter Standalone Client进行虚拟机 P2V提示 权限不足,无法连接\\ip\admin$的解决方法集锦
使用VMware vCenter Converter Standalone Client进行虚拟机 P2V提示 权限不足,无法连接\\ip\admin$的解决方法集锦 步骤一 检查 远程桌面到&quo ...
- Linux执行.sh文件,提示No such file or directory的问题的解决方法
亲测有效:http://www.jb51.net/LINUXjishu/56395.html Linux执行.sh文件,提示No such file or directory的问题的解决方法 在win ...
- php 字符串中的\n换行符无效、不能换行的解决方法
php 字符串中的\n换行符无效.不能换行的解决方法 程序的中的换行符\n会直接输出,无法正确换行,解决方法是把单引号改为双引号 aa
- 使用phpExcelReader操作excel提示The filename *.xls is not readable的详细解决方法
使用phpExcelReader操作excel提示The filename *.xls is not readable的详细解决方法 是xls文件有问题,另存为新的xls文件,然后导入就不会有这个问题
随机推荐
- VBA_BASIC
字符串相关 判断单元格是否包含特定字符串,以"P"为例. if cells(1,1) Like "*P*" Then cells(1,2) = "ha ...
- Oracle部署,关于日志文件系统选择(硬盘格式化、挂载)
之前部署过好多Oracle服务,采用的日志文件系统一直是ext3.但是我观察到很多人在格式化/挂载数据盘时,采用的日志文件系统类型有ext3.ext4.xfs等,这不禁让我发出疑问,哪个类型的数据处理 ...
- MongoDB导入导出备份数据
需要提前安装mongodb-database-tools参考:centos离线安装mongodb-database-tools 导出数据 常用的导出有两种:mongodump和mongoexport, ...
- mindxdl--common--log_record.go
// Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved.// Package common define co ...
- go工具pprof部署
在做内存分析时,用到了pprof,这里做一下部署介绍和入门级别的使用. pprof是golang的性能工具,有两种交互方式:命令行交互和web交互,同时还支持性能分析数据的图形化展示. 部署pprof ...
- golang 概念理解
https://www.youtube.com/watch?v=cN_DpYBzKso https://blog.golang.org/gos-declaration-syntax 1.golang ...
- 优雅的重启uwsgi 告别uwsgi reload过程中造成的无法请求、请求延迟等问题
[uwsgi]#使用优雅重启 lazy-apps = true #监听monitor文件 当monitor文件发生改变是重启uwsgi touch-chain-reload = /home/monit ...
- Spring Security(3)
您好,我是湘王,这是我的博客园,欢迎您来,欢迎您再来- 前面运行写好的代码之所以没有任何显示,是因为还没有对Spring Security进行配置,当然啥也不显示了.这就好比你坐在车上,却不打开发动机 ...
- DP?
杨斌涵//aad69d38 分治优化DP 分治优化1D/1D dp 对于一类 \[f(x) = \min_{k = y}^{x - 1} w(l, r) \] 即所有 \(w(l,r)\) 事先已知, ...
- Springboot2.6集成Email
Springboot集成Email 老版本 这时候的JavaMailSender是受到Spring的托管的,我们只需要配置参数就行了 !如何判断是否是被Springboot托管的:以下代码IDEA会自 ...