【问题标题】:Selenium python: Can not connect to the Service %s" % self.pathSelenium python: 无法连接到服务 %s" % self.path
【发布时间】:2016-02-25 10:29:25
【问题描述】:

我正在尝试使用 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

请告知如何解决这个问题

【问题讨论】:

标签: python selenium


【解决方案1】:

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

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

0.0.0.0            localhost

到:

127.0.0.1 localhost

这解决了我的 Selenium 问题。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      对于 MAC 系统: 将主机文件更改为默认值,如下所示: 1. Command+Shift+G 进入 /private/etc/hosts 2.在文本文件中打开 3.文件>另存为并取消选中“如果未提供扩展名,请使用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
      

      【讨论】:

      • 您应该在答案本身中提供所有必要的内容,而不仅仅是其中的一部分。换句话说,答案应该是独立的。
      猜你喜欢
      • 1970-01-01
      • 2016-12-16
      • 2010-11-13
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-20
      • 1970-01-01
      相关资源
      最近更新 更多