我正在尝试使用 python 脚本运行硒测试,但在执行测试时收到以下错误:
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
请告知如何解决此问题
在谷歌搜索了一段时间后,并尝试了各种解决方案。我在这里找到了对我有用的那个:https://github.com/SeleniumHQ/selenium/issues/2903#issuecomment-272112510
如该评论中所述,尝试将127.0.0.1 localhost
添加到/etc/hosts
对于 MAC 系统:将主机文件更改为默认值,如下所示:1. 命令+Shift+G 转到/private/etc/hosts2.在文本文件中打开3. 文件>另存为并取消选中"如果未提供扩展名,请使用 txt"框并重命名主机4.Go 终端执行命令猫/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
对于 Windows C:\Windows\System32\drivers\etc\hosts
以管理员身份打开记事本,然后打开文件主机并执行所需的所有更改,在我的特定情况下是:
0.0.0.0 localhost
自:
127.0.0.1 localhost
这解决了我对硒的问题。