selenium.common.exceptions.WebDriverException:消息:未知错误:通过InstaPy和selenium执行测试时无法发现打开的页面

时间:2018-07-26 07:03:02

标签: python google-chrome selenium selenium-webdriver selenium-chromedriver

我想在基于this instructions的Windows上运行InstaPy 所以我将其安装到第3步,然后进入高级设置。因为简单的设置对我不起作用。 现在,我已经从an .exe setup file安装了GUI工具,运行该漫游器会打开一个chrome页面,过一会儿我收到错误提示。我该怎么办?我哪里出问题了?

我是google chrome版本68.0.3440.75(正式版本)(64位),目前我使用的是chromedriver.exe版本2.4和python 3.6.5

首先,我看到此Chrome页面: enter image description here

之后,我在GUI中看到此错误 enter image description here 错误是这个

Error: ERROR [2018-07-26 11:16:27] [mohammad.f.rasoulnejad] Message: unknown error: unable to discover open pages
 (Driver info: chromedriver=2.4.226107,platform=Windows NT 6.3 x86_64)
 Traceback (most recent call last):
 File "C:\Users\Mohammad\Desktop\InstaPy\instapy\instapy.py", line 295, in set_selenium_local_session
 chrome_options=chrome_options)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
 desired_capabilities=desired_capabilities)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
 self.start_session(desired_capabilities, browser_profile)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
 response = self.execute(Command.NEW_SESSION, capabilities)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
 self.error_handler.check_response(response)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
 raise exception_class(message, screen, stacktrace)
 selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
 (Driver info: chromedriver=2.4.226107,platform=Windows NT 6.3 x86_64)

 Traceback (most recent call last):
 File "C:\Users\Mohammad\Desktop\InstaPy\instapy\instapy.py", line 295, in set_selenium_local_session
 chrome_options=chrome_options)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
 desired_capabilities=desired_capabilities)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
 self.start_session(desired_capabilities, browser_profile)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
 response = self.execute(Command.NEW_SESSION, capabilities)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
 self.error_handler.check_response(response)
 File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
 raise exception_class(message, screen, stacktrace)
 selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
 (Driver info: chromedriver=2.4.226107,platform=Windows NT 6.3 x86_64)


 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
 File "quickstart.py", line 3, in <module>
 session = InstaPy(username='mohammad.f.rasoulnejad', password='myPassword')
 File "C:\Users\Mohammad\Desktop\InstaPy\instapy\instapy.py", line 188, in __init__
 self.set_selenium_local_session()
 File "C:\Users\Mohammad\Desktop\InstaPy\instapy\instapy.py", line 299, in set_selenium_local_session
 Settings.chromedriver_location))
 instapy.instapy.InstaPyError: ensure chromedriver is installed at C:\Users\Mohammad\Desktop\InstaPy\assets\chromedriver
InstaPy ended

更新: 我下载了2.40并将其放在资源文件夹中,但将其2.4.226107放在了错误消息中 chromedriver = 2.4.226107

DevTools listening on ws://127.0.0.1:12969/devtools/browser/c5a3dd55-34fb-4723-9161-6b8a6e469b29
ERROR [2018-07-26 12:58:34] [mohammad.f.rasoulnejad]  Message: unknown error: unable to discover open pages
  (Driver info: chromedriver=2.4.226107,platform=Windows NT 6.3 x86_64)
Traceback (most recent call last):
  File "C:\Users\Mohammad\Desktop\InstaPy\instapy\instapy.py", line 295, in set_selenium_local_session
    chrome_options=chrome_options)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
  (Driver info: chromedriver=2.4.226107,platform=Windows NT 6.3 x86_64)

Traceback (most recent call last):
  File "C:\Users\Mohammad\Desktop\InstaPy\instapy\instapy.py", line 295, in set_selenium_local_session
    chrome_options=chrome_options)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "D:\web\Python 3.6.5\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
  (Driver info: chromedriver=2.4.226107,platform=Windows NT 6.3 x86_64)


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "quickstart.py", line 3, in <module>
    session = InstaPy(username='mohammad.f.rasoulnejad', password='myPassword')
  File "C:\Users\Mohammad\Desktop\InstaPy\instapy\instapy.py", line 188, in __init__
    self.set_selenium_local_session()
  File "C:\Users\Mohammad\Desktop\InstaPy\instapy\instapy.py", line 299, in set_selenium_local_session
    Settings.chromedriver_location))
instapy.instapy.InstaPyError: ensure chromedriver is installed at C:\Users\Mohammad\Desktop\InstaPy\assets\chromedriver

1 个答案:

答案 0 :(得分:1)

此错误消息...

Message: unknown error: unable to discover open pages

...表示 ChromeDriver 无法通过 Chrome浏览器启动/产生新的 WebBrowsing 会话。

您的主要问题是所使用的二进制版本之间的不兼容性

  • 您正在使用 chromedriver = 2.4
  • chromedriver = 2.4 很老了,还很古老。
  • 您正在使用 Google Chrome版本68.0.3440.75(正式版本)(64位)
  • ChromeDriver v2.40的发行说明中明确提到以下内容:
  

支持 Chrome v66-68

因此 ChromeDriver v2.4 Chrome浏览器v68.0 之间存在明显的不匹配


解决方案

  • 按照Release Notes使用 Google Chrome版本68.0.3440.75 时,您需要使用兼容的 ChromeDriver 二进制文件。
  • ChromeDriver - WebDriver for Chrome下载兼容的 ChromeDriver 二进制文件,即 ChromeDriver v2.40 (2018-06-07)。

更新

如前所述,即使升级到 chromedriver = 2.40 后,您仍将 ChromeDriver 版本设置为 chromedriver = 2.4 ,您可以覆盖明确提及参数executable_path如下,是 OS PATH 中的早期版本:

from selenium import webdriver

driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')