【问题标题】:Python Selenium "Can not connect to the Service %s" % self.path in linux serverPython Selenium“无法连接到服务%s”%self.path在linux服务器中
【发布时间】:2018-06-08 03:51:14
【问题描述】:

Traceback (most recent call last):

  File "testing.py", line 20, in <module>
    driver = webdriver.Chrome(executable_path="/home/cavema11/public_html/testing.py")
  File "/opt/python-3.6.4/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()
  File "/opt/python-3.6.4/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 104, in start
    raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service /home/cavema11/public_html/testing.py

我的 /etc/hosts 中有 127.0.0.1 localhost,但仍然出现此错误。

请帮帮我。

谢谢

【问题讨论】:

  • 您检查服务是否在线?

标签: python-3.x selenium google-chrome selenium-webdriver selenium-chromedriver


【解决方案1】:

通过参数executable_path,您需要传递ChromeDriver 的绝对路径,而不是任何其他文件。所以你需要改变:

driver = webdriver.Chrome(executable_path="/home/cavema11/public_html/testing.py")

收件人:

driver = webdriver.Chrome(executable_path='/path/to/chromedriver')

更新

  • 确保您已从download location 下载了与您的底层操作系统相关的 ChromeDriver 二进制文件的确切格式:

    • chromedriver_linux64.zip:适用于 Linux 操作系统
    • chromedriver_mac64.zip:适用于 Mac OSX
    • chromedriver_win32.zip:适用于 Windows 操作系统
  • 确保/etc/hosts 文件包含以下条目:

    127.0.0.1 localhost 
    
  • 确保 ChromeDriver 二进制文件对 非 root 用户具有可执行权限。

  • 确保您通过参数executable_path 传递了正确的ChromeDriver 二进制文件的绝对路径。 (chmod 777)
  • 非root用户身份执行您的测试

【讨论】:

  • 感谢您的回复。我更改后出现另一个错误。这是错误: OSError: [Errno 8] Exec format error: '/home/cavema11/public_html/chromedriver.exe'
  • 您使用的是 Linux OS 并且需要删除扩展部分,如.exe
  • @user9912010 查看我更新的答案,让我知道状态。
  • 我现在收到此错误“消息:未知错误:找不到 Chrome 二进制文件”
  • 感谢您的帮助@DebanjanB
猜你喜欢
  • 1970-01-01
  • 2016-12-16
  • 1970-01-01
  • 2010-11-13
  • 2012-01-24
  • 1970-01-01
  • 1970-01-01
  • 2014-08-20
  • 2020-01-24
相关资源
最近更新 更多