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

Jan*_*ill 6 selenium google-chrome python-3.x selenium-chromedriver selenium-webdriver

当我使用 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')
Run Code Online (Sandbox Code Playgroud)

发生错误:

   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)
Run Code Online (Sandbox Code Playgroud)

有人能帮我吗?谢谢。

小智 11

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

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()
Run Code Online (Sandbox Code Playgroud)

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


小智 9

如果您有options.add_argument("--remote-debugging-port=9222")将其更改为options.add_argument("--remote-debugging-port=9230")

或者只是简单地添加 options.add_argument("--remote-debugging-port=9230") 在我的情况下修复。


Deb*_*anB 4

这个错误信息...

selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer
Run Code Online (Sandbox Code Playgroud)

...意味着ChromeDriver无法启动/生成新的WebBrowserChrome 浏览器会话。

你需要考虑一个事实:

注意路径本身是原始路径,因此您不需要添加r或删除开关。

此外,请确保/etc/hosts您的系统上包含以下条目:

127.0.0.1 localhost.localdomain localhost
#or
127.0.0.1 localhost loopback
Run Code Online (Sandbox Code Playgroud)