python - WebDriverException : Message: 'Can not connect to the ChromeDriver' . utils.is_connectable(self.port) 错误:

标签 python selenium selenium-webdriver selenium-chromedriver

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

/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")

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

最佳答案


适用于 Linux

1. 检查您是否安装了最新版本的 chrome brwoser-> "chromium-browser -version"
2. 如果没有,安装最新版本的 chrome “sudo apt-get install chromium-br/>”
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()

关于python - WebDriverException : Message: 'Can not connect to the ChromeDriver' . utils.is_connectable(self.port) 错误:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24900922/

相关文章:

python - 当我使用 python 将日期时间从 csv 文件插入 mysql 时出现错误

selenium - 如何使用 Selenium 处理 IE [Windows 10] 中弹出的 Windows Security

java - java中的 Selenium 异常(org.openqa.selenium.remote.UnreachableBrowserException)

javascript - 运行 Cucumber 测试时禁用 JavaScript

java - 如何在 github 中使用 Selenium Web Driver 管理弹出窗口

java - 如何循环浏览 WebElement 列表并选择一个具有条件的 WebElement?

python - 只有一条彩色线的 Seaborn 多线图

python - 使用 Pandas 循环根据两列中的条件组合创建新的数据框

python - 使用 XMLtree 或 MINIDOM 进行 XML 解析

selenium - 无法使用 Java/Selenium 脚本读取 Excel 工作表中存在的所有数据