SessionNotCreatedException:消息:未从断开连接创建会话:无法使用 ChromeDriver 2.45 Chrome v71 连接到渲染器

2023-11-27

当我使用 Python 使用 Selenium 执行此代码时:

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome(executable_path=r'/Users/qa/Documents/Python/chromedriver')

发生错误:

   Traceback (most recent call last):
  File "/Users/qa/Documents/Python/try.py", line 4, in <module>
    driver = webdriver.Chrome(executable_path=r'/Users/qa/Documents/Python/chromedriver')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer
  (Session info: chrome=71.0.3578.98)
  (Driver info: chromedriver=2.44.609545 (c2f88692e98ce7233d2df7c724465ecacfe74df5),platform=Mac OS X 10.13.6 x86_64)

有人能帮我吗?谢谢。


我遇到了类似的错误,首先收到错误消息:

selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:正常退出。 (未知错误:DevToolsActivePort 文件不存在)

通过添加解决了这个问题options.add_argument("--remote-debugging-port=9230")到 ChromeOptions()。程序运行一次,我得到了与上面相同的错误消息:

selenium.common.exceptions.SessionNotCreatedException:消息:会话未创建 已断开连接:无法连接到渲染器 (会话信息:headless chrome=89.0.4389.114)

这里的问题是 chrome 进程没有在程序中正确关闭,因此该进程在调试端口上仍然处于活动状态。要解决此问题,请关闭活动端口sudo kill -9 $(sudo lsof -t -i:9230)并将以下行添加到代码末尾:

driver.stop_client()
driver.close()
driver.quit()

由于我在任何地方都没有找到这个答案,我希望它对某人有所帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SessionNotCreatedException:消息:未从断开连接创建会话:无法使用 ChromeDriver 2.45 Chrome v71 连接到渲染器 的相关文章

随机推荐