Python selenium WebDriverException:打开ChromeDriver时无法访问chrome

时间:2018-04-11 04:22:20

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

我正在使用Selenium Chrome Webdriver在Python 3中打开网页。 我想有一个可以打开网页的功能。 我最初有:

   setModalVisible(visible) {
     this.setState({modalVisible: visible});
   }

我把它放到函数goTo()

driver = webdriver.Chrome(executable_path=r'C:\Users\alice\Desktop\chromedriver')
driver.get('https://reports.blm.gov/report/LR2000/23/Pub-MC-Geo-Index')

但是,我无法在该goTo函数之外的该页面上执行任何其他操作。当我尝试时我得到错误:

def goTo():
    driver = webdriver.Chrome(executable_path=r'C:\Users\alice\Desktop\chromedriver')
    driver.get('https://reports.blm.gov/report/LR2000/23/Pub-MC-Geo-Index')

有谁知道如何使用函数正确打开页面?

1 个答案:

答案 0 :(得分:4)

错误说明了一切:

WebDriverException: chrome not reachable
  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64)

您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:

  • 您正在使用 chromedriver = 2.35
  • chromedriver=2.35的发行说明明确提及以下内容:
  

支持 Chrome v62-64

  • 您正在使用 chrome = 65.0
  • ChromeDriver v2.36的发行说明明确提及以下内容:
  

支持 Chrome v64-66

因此 ChromeDriver 版本( v2.35 )与 Chrome浏览器版本( v65)之间存在明显的不匹配。 0

解决方案

  • Selenium 升级到当前级别Version 3.11.0
  • ChromeDriver 升级到当前ChromeDriver v2.37级别。
  • Chrome 版本保留在 Chrome v65.x 级别。 (as per ChromeDriver v2.37 release notes
  • 通过 IDE 清理您的项目工作区仅使用所需的依赖项重建项目
  • 使用CCleaner工具清除执行测试套件之前和之后的所有操作系统杂务。
  • 如果您的基本 Web客户端版本太旧,请通过Revo Uninstaller将其卸载并安装最新的GA和已发布的 Web客户端版本。
  • 进行系统重启
  • 执行@Test
  • 始终在driver.quit()方法中调用tearDown(){}以关闭&正常销毁 WebDriver Web客户端实例。