关于Can not connect to the Service chromedriver

本文介绍了在使用Selenium WebDriver过程中遇到的无法启动浏览器的问题及解决方法。问题出现的原因包括hosts文件配置错误和Windows防火墙阻止连接。通过修复hosts文件并添加localhost映射,以及临时关闭防火墙,最终解决了Selenium WebDriver的启动问题。

今天selenium遇到这个错误。。搞了一个早上,以为是chromedriver版本对应不对,后来尝试火狐之类的,都没成功。。。

最终发现,原因出在两个,

1. C:\Windows\System32\drivers\etc目录下的hosts文件不知道什么时候被修改了。

解决方法:打开文件,居然空空如也。。(后来使用软件恢复后发现有的也只有注释,跟空空如也没区别)

添加下面一行

127.0.0.1       localhost

解决√


添加了之后,还是没办法。心里千万只草泥马在奔腾

2. ping了一下localhost,一般故障,发现原因,windows防火墙作祟

解决方法,关闭windows防火墙, 使用小娜打开控制面板→系统与安全→windows defender防火墙




关闭防火墙后,启动成功

解决√

Traceback (most recent call last): File "D:\python主要文件\间歇努力\.venv\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 64, in _binary_paths raise ValueError(f"The path is not a valid file: {path}") ValueError: The path is not a valid file: chromedriver.exe The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\python主要文件\间歇努力\damai.py", line 181, in <module> con = Concert() ^^^^^^^^^ File "D:\python主要文件\间歇努力\damai.py", line 43, in __init__ self.driver = webdriver.Chrome(service=service) # 当前浏览器驱动对象 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python主要文件\间歇努力\.venv\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 47, in __init__ super().__init__( File "D:\python主要文件\间歇努力\.venv\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 53, in __init__ if finder.get_browser_path(): ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\python主要文件\间歇努力\.venv\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 47, in get_browser_path return self._binary_paths()["browser_path"] ^^^^^^^^^^^^^^^^^^^^ File "D:\python主要文件\间歇努力\.venv\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 78, in _binary_paths raise NoSuchDriverException(msg) from err selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
最新发布
08-30
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值