WebDriverException:消息:'无法连接到ChromeDriver'.utils.is_connectable(self.port)中的错误:

kvm*_*006 7 python selenium selenium-chromedriver selenium-webdriver

我正在尝试使用chromedriver 2.10在Chrome浏览器版本35.0.1916.114上运行我的测试在CentOS机器上

/home/varunm/EC_WTF_0.4.10/EC_WTF0.4.10_Project/wtframework/wtf/drivers/chromedriver

实际上我修复了路径问题,因为如果问题是路径,则错误消息不同

    def start(self):
    """
    Starts the ChromeDriver Service.

    :Exceptions:
     - WebDriverException : Raised either when it can't start the service
       or when it can't connect to the service
    """
    env = self.env or os.environ
    try:
        self.process = subprocess.Popen([
          self.path,
          "--port=%d" % self.port] +
          self.service_args, env=env, stdout=PIPE, stderr=PIPE)
    except:
        raise WebDriverException(
            "ChromeDriver executable needs to be available in the path. \
            Please download from http://chromedriver.storage.googleapis.com/index.html\
            and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
    count = 0
    while not utils.is_connectable(self.port):
        count += 1
        time.sleep(1)
        if count == 30:
             raise WebDriverException("Can not connect to the ChromeDriver")
Run Code Online (Sandbox Code Playgroud)

如果路径错误,我将收到一些其他错误,但现在错误是在建立连接时

Vic*_*cky 19


对于Linux

1.检查您是否安装了最新版本的chrome brwoser-> "chromium-browser -version"
2.如果没有,请安装最新版本的chrome "sudo apt-get install chromium-browser"
3.获取相应版本的chrome驱动程序从以下链接http://chromedriver.storage.googleapis.com/index.html
4.解压缩chromedriver.zip
5.将文件移动到/ usr/bin /目录sudo mv chromedriver/usr/bin /
6.转到/ usr/bin /目录,你需要运行类似" chmod a + x chromedriver "的东西来标记它的可执行文件.
7.最后你可以执行代码.

import os
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()
Run Code Online (Sandbox Code Playgroud)


小智 17

验证127.0.0.1 localhost行已添加到/ etc/hosts文件中并取消注释.对于我的一些同事来说这是个问题,我在删除这一行之后能够重现它.添加它可以解决问题.

  • 在我的情况下,这是废话 (2认同)