chromedriver SessionNotCreatedException

时间:2018-02-23 19:21:50

标签: python python-2.7 selenium selenium-webdriver selenium-chromedriver

我尝试使用seleniumchromedriver从网站上抓取文件。我已将chrome和chromedriver更新到当前级别,但收到以下消息:

Traceback (most recent call last):
  File "<stdin>", line 128, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created exception
from timeout: Timed out receiving message from renderer: 600.000
  (Session info: chrome=64.0.3282.167)
  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.10.0-40-generic x86_64)

是否有处理此错误的建议? SessionNotCreatedException是由页面超时引起的。

1 个答案:

答案 0 :(得分:0)

错误确实给了我们一些提示:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created exception
from timeout: Timed out receiving message from renderer: 600.000
  (Session info: chrome=64.0.3282.167)
  (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.10.0-40-generic x86_64)

一个简单的解决方案是将Key executable_path ChromeDriver 二进制文件的绝对路径的Value一起传递,同时初始化 WebDriver Web浏览器实例如下:

from selenium import webdriver

driver = webdriver.Chrome(executable_path="/usr/local/lib/python2.7/dist-packages/chromedriver_binary/chromedriver")
driver.get("http://www.google.com")

另外确保您正在使用:

  • 最新的 JDK 版本,即Java SE Development Kit 8u161
  • 最新的 Selenium Python客户端,即Selenium 3.9.0
  • 测试之前和之后,从 IDE 中清除项目空间
  • 运行CCleaner工具,在执行测试套件之前和之后清除操作系统杂务。
  • 如果 Chrome 的基本版本太旧,请通过Revo Uninstaller卸载 Chrome 并安装最新的GA发布版 Chrome
  • 执行测试