Selenium python:无法连接到服务%s" %self.path

时间:2016-02-25 10:29:26

标签: python selenium

我正在尝试使用python脚本运行selenium测试,但是在执行测试时我收到以下错误:

Traceback (most recent call last):
File "/var/www/html/selenium-scripts/example.py", line 13, in <module>
driver = webdriver.Chrome()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 61, in __init__self.service.start()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 88, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

请告知如何解决此问题

3 个答案:

答案 0 :(得分:3)

谷歌搜索一段时间后,尝试各种解决方案。我在这里找到了适合我的那个: https://github.com/SeleniumHQ/selenium/issues/2903#issuecomment-272112510

如该评论中所述,尝试将127.0.0.1 localhost添加到/ etc / hosts

答案 1 :(得分:1)

对于MAC系统: 将主机文件更改为默认值,如下所示: 1. Command + Shift + G转到/ private / etc / hosts 2.打开文本文件 3.文件&gt;保存并取消选中“如果没有提供扩展使用txt”框并重命名主机 4.Go终端执行命令cat / etc / hosts 检查它是否显示

##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost

答案 2 :(得分:0)

对于Windows C:\ Windows \ System32 \ drivers \ etc \ hosts

以管理员身份打开记事本,然后打开文件主机并进行所需的所有更改,在我的特定情况下为:

0.0.0.0            localhost

收件人:

127.0.0.1 localhost

解决了我与硒有关的问题。