Python selenium WebDriverException:打开 ChromeDriver 时无法访问 chrome [英] Python selenium WebDriverException: chrome not reachable while opening ChromeDriver
问题描述
我正在使用 Selenium Chrome Webdriver 在 Python 3 中打开网页.我想要一个可以打开网页的功能.我原来有:
I am using Selenium Chrome Webdriver to open a webpage in Python 3. I would like to have a function that can open the webpage. I originally had:
driver = webdriver.Chrome(executable_path=r'C:UsersaliceDesktopchromedriver')
driver.get('https://reports.blm.gov/report/LR2000/23/Pub-MC-Geo-Index')
我把它放入一个函数 goTo()
I put it in to a function goTo()
def goTo():
driver = webdriver.Chrome(executable_path=r'C:UsersaliceDesktopchromedriver')
driver.get('https://reports.blm.gov/report/LR2000/23/Pub-MC-Geo-Index')
但是,除了 goTo 函数之外,我无法在该页面上执行任何其他操作.尝试时出现错误:
However, I was unable to do any other action on that page outside of that goTo function. When try I get error:
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)
有谁知道如何使用函数正确打开页面?
Does anyone knows how can I open the a page properly using a function?
推荐答案
错误说明了一切:
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)
您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:
Your main issue is the version compatibility between the binaries you are using as follows :
- 您正在使用 chromedriver=2.35
- 清楚发布chromedriver=2.35的发布说明提到以下内容:
支持 Chrome v62-64
- 您正在使用 chrome=65.0
- ChromeDriver v2.36 的发行说明明确提到以下内容:
- 将 Selenium 升级到当前级别版本 3.11.0.
- 将 ChromeDriver 升级到当前的 ChromeDriver v2.37 级别.
- 将 Chrome 版本保持在 Chrome v65.x 级别.(根据 ChromeDriver v2.37 版本说明)
- 清理您的项目工作区,通过您的 IDE 并重建您的项目,仅使用所需的依赖项.
- 使用 CCleaner 工具清除之前和之后的所有操作系统杂事执行测试套件.
- 如果您的基本Web Client 版本太旧,请通过Revo Uninstaller 并安装 Web Client 的最新 GA 和发布版本.
- 进行系统重启.
- 执行您的
@Test
. - 总是在
tearDown(){}
方法中调用driver.quit()
来关闭 &优雅地销毁 WebDriver 和 Web Client 实例. - Upgrade Selenium to current levels Version 3.11.0.
- Upgrade ChromeDriver to current ChromeDriver v2.37 level.
- Keep Chrome version at Chrome v65.x levels. (as per ChromeDriver v2.37 release notes)
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
- If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
- Take a System Reboot.
- Execute your
@Test
. - Always invoke
driver.quit()
withintearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.
支持 Chrome v64-66
因此 ChromeDriver 版本 (v2.35) 和 Chrome 浏览器 版本 (v65.0)
So there is a clear mismatch between the ChromeDriver version (v2.35) and the Chrome Browser version (v65.0)
这篇关于Python selenium WebDriverException:打开 ChromeDriver 时无法访问 chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!