selenium.common.exceptions.SessionNotCreatedException:消息:会话未创建,Selenium python

时间:2020-03-29 16:01:17

标签: python python-3.x selenium

我有一个问题,每一次, 时间 基本上这是我的代码:

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

options = Options()
options.binary_location = "C:\Program Files (x86)\Google\Chrome Beta\Application\chrome.exe"
options.add_argument("--no-sandbox")
options.add_argument("--no-default-browser-check")
options.add_argument("--no-first-run")
options.add_argument("--disable-default-apps")
driver = webdriver.Chrome(options=options, executable_path="C:\Program Files (x86)\Google\Chrome Beta\Application\chromedriver.exe")
driver.get('https://www.youtube.com/')


,错误是

selenium.common.exceptions.SessionNotCreatedException: Message: session not created

我使用了Pycharm,并尝试将VS代码与python 3.4、3.7和3.8.3结合使用 请帮助我,我对此已经感到厌倦了。

完整错误日志:

Traceback (most recent call last):
  File "C:/Users/um/PycharmProjects/Selenium/main.py", line 10, in <module>
    driver = webdriver.Chrome(options=options, executable_path="C:\Program Files (x86)\Google\Chrome Beta\Application\chromedriver.exe")
  File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\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 send message to renderer
  (Session info: chrome=81.0.4044.83)

2 个答案:

答案 0 :(得分:0)

您的错误不是

无法将消息发送到渲染器

如您所说。根据堆栈跟踪,您将问题发布到了第6行

driver = webdriver.Chrome(options=options, executable_path="chromedriver.exe", )

问题是:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created

似乎您为chromedriver指定了无效的路径,而Selenium无法初始化驱动程序并创建会话。 您还应该check the version of the chromedriver with the guideHere您可以下载有效版本(我已从堆栈跟踪中获取Chrome版本)。

答案 1 :(得分:0)

是的,它确实开始了,然后关闭了上面的错误日志,而且我的版本正确