selenium.common.exceptions.WebDriverException:消息:未知错误:无法通过 Selenium 使用 ChromeDriver 发现打开的页面 [英] selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages using ChromeDriver through Selenium

查看:32
本文介绍了selenium.common.exceptions.WebDriverException:消息:未知错误:无法通过 Selenium 使用 ChromeDriver 发现打开的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 selenium 的新手,只是想学习.当尝试通过 ChromeDriver 打开 Chrome 浏览器时,出现以下错误:

I am a newbie to selenium just trying to learn. When tried opening Chrome browser through ChromeDriver I got the below error:

Traceback (most recent call last):
  File "selenium_practise1_chrome.py", line 5, in <module>
    driver = webdriver.Chrome()
  File "C:UserskulokeshAppDataLocalProgramsPythonPython36libsite-packagesseleniumwebdriverchromewebdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "C:UserskulokeshAppDataLocalProgramsPythonPython36libsite-packagesseleniumwebdriver
emotewebdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:UserskulokeshAppDataLocalProgramsPythonPython36libsite-packagesseleniumwebdriver
emotewebdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:UserskulokeshAppDataLocalProgramsPythonPython36libsite-packagesseleniumwebdriver
emotewebdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:UserskulokeshAppDataLocalProgramsPythonPython36libsite-packagesseleniumwebdriver
emoteerrorhandler.py", line 242, 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.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=a lotows NT 6.1.7601 SP1 x86_64)

尝试了很多谷歌搜索,但没有任何帮助.以下是我的代码:

Tried alot of googling but nothing helped. Below is my code:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get('http://www.python.org')
print(driver.title)

这不是要处理的代码,但我很困惑我在这里缺少什么.另外请推荐一些好的在线资源来学习 Python Selenium.我打开的 chrome 如下所示:

This is not a code to deal with but I am confused what am I missing here. Also please suggest some good online resource to learn Python Selenium. My chrome opened was looking like below:

推荐答案

这个错误信息...

selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=a lotows NT 6.1.7601 SP1 x86_64)

...暗示 ChromeDriver 无法启动/生成新的 WebBrowserChrome 浏览器 会话.

...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.

通过 ChromeOptions() 将参数 --no-sandbox 添加到现有代码中,如下所示:

Add the argument --no-sandbox through ChromeOptions() to your existing code as follows:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--no-sandbox') # Bypass OS security model
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:path	ochromedriver.exe')
driver.get('http://www.python.org')
print(driver.title)
driver.quit()

<小时>

其他注意事项

  • Selenium 升级到当前级别版本 3.14.0.李>
  • ChromeDriver 升级到当前的 ChromeDriver v2.41 级别.
  • Chrome 版本保持在 Chrome v66-68 级别之间.(根据 ChromeDriver v2.41 发行说明)
  • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖.
  • 执行你的 @Test.
  • 总是在 tearDown(){} 方法中调用 driver.quit() 来关闭 &优雅地销毁 WebDriverWeb Client 实例.

  • Additional considerations

    • Upgrade Selenium to current levels Version 3.14.0.
    • Upgrade ChromeDriver to current ChromeDriver v2.41 level.
    • Keep Chrome version between Chrome v66-68 levels. (as per ChromeDriver v2.41 release notes)
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • Execute your @Test.
    • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
    • 这篇关于selenium.common.exceptions.WebDriverException:消息:未知错误:无法通过 Selenium 使用 ChromeDriver 发现打开的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆