python版selenium浏览器驱动问题Can not connect to the Service chromedriver解决

  • A+
所属分类:python自动化

对比Java,Python到底好在哪儿?

最近在Windows10 64位操作系统中使用selenium2自动化工具好好的,突然有一天不能使用了,无法驱动浏览器,报如下错误:

raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

想着是不是最近升级了selenium或者浏览器导致的,于是又重新各种折腾,网上查资料,后来终于知道原因了,现在特别留着记录,以共大家参考:

首先,要保证selenium和对应版本的浏览器驱动是已经正确安装了。

其次,在C:\Windows\System32\drivers\etc\目录内找到hosts并用记事本或notepad++(最好是用该工具)打开文件,将127.0.0.1    localhost这一句添加到里面并保存。

最后,运行cmd后  ping localhost  若运行正常没有出现一般故障则可以正常使用selenium了,若出现一般故障则需要将电脑的防火墙关闭后再ping localhost 直到接收正常。

总结,selenium的错误Can not connect to the Service chromedriver是一个莫名其妙的bug,这里再次提醒大家,若出现类似错误,一是检查hosts中是否有添加127.0.0.1 localhost(前面不能有#),二是要通过cmd命令ping localhost 直到正常接收数据包,若没有就去关闭防火墙。这个问题的解决方式应该是同样使用于其他操作系统如:Linux 或其他版本的工具如:Java等,可以借鉴参考。

weinxin
我的微信公众号
爱真理,得永生!          爱在灵灵久博客,网罗天下,福利大家!

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: