python 报 selenium.common.exceptions.SessionNotCreatedException

这篇具有很好参考价值的文章主要介绍了python 报 selenium.common.exceptions.SessionNotCreatedException。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

今天做selenium项目更新,莫名其妙报了SessionNotCreatedException 错误,显示错误如下:

  File "D:\Program Files\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 89, in __init__
    keep_alive,
  File "D:\Program Files\Python37\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 112, in __init__
    options=options,
  File "D:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "D:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "D:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "D:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Missing or invalid capabilities
  (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 10.0.18363 x86_64)

显示不是chromedriver与chrome版本不兼容问题。后面脑回路,终于知道原因。

之前可能安装了其它包把selenium版本更新到了4.x.x。猜测这个版本对chrome版本有最低要求。经过升级chrome版本与chromedriver,测试了下也确实能正常。懒得去追根溯源了,解决方案:

1)安装回selenium 3版本,目前最后一版3的版本号是3.141.0:

pip install selenium==3.141.0

2)升级chrome与chromedriver到较新版。记selenium4 使用services设置chromedriver路径:文章来源地址https://www.toymoban.com/news/detail-643291.html

from selenium.webdriver.chrome.service import Service as ChromeService
......
s = ChromeService(executable_path=driver_path)
webdriver.Chrome(service=s, options=options)

到了这里,关于python 报 selenium.common.exceptions.SessionNotCreatedException的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包