Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SessionNotCreatedException: Message: session not created from disconnected: unable to connect to renderer with ChromeDriver 2.45 Chrome v71

When I'm executing this code with Selenium using Python:

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

The error occurred:

   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)

Can someone help me? Thanks.

like image 396
Jan Vill Avatar asked Dec 17 '18 03:12

Jan Vill


3 Answers

This error message...

selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer

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

You need to consider a fact:

  • As you are using Mac OS X the Key executable_path must be supported with a Value as :

    '/Users/qa/Documents/Python/chromedriver'
    
  • So line will be:

    driver = webdriver.Chrome(executable_path='/Users/qa/Documents/Python/chromedriver')
    

Note: The path itself is a raw path so you don't need to add the switch r and drop it.

Additionally, ensure that /etc/hosts on your system contains the following entry :

127.0.0.1 localhost.localdomain localhost
#or
127.0.0.1 localhost loopback
like image 176
undetected Selenium Avatar answered Oct 21 '22 06:10

undetected Selenium


Running into this same issue on linux, specifically a raspberry pi 4 (so arm cpu). i used the chromium-browser and chromium-chromedriver package.

This is my code:

browser = Chrome(executable_path = '/usr/bin/chromedriver', options = opts)

and this is the error message:

File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/ubuntu/Documents/reliant-scrape/reliant_scrape.py", line 296, in <module>
    output = logon(config['headless'], config['download'], config['site'], config['creds'])
  File "/home/ubuntu/Documents/reliant-scrape/reliant_scrape.py", line 75, in logon
    browser = Chrome(executable_path = '/usr/bin/chromedriver', options = opts)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/ubuntu/.local/lib/python3.8/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: headless chrome=88.0.4324.150)

Yet when I run chromedriver by itself it works fine? I added the line to /etc/hosts as well but that didn't help.

like image 22
steven hurwitt Avatar answered Oct 21 '22 05:10

steven hurwitt


I had a similar error, first getting the error message:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally. (unknown error: DevToolsActivePort file doesn't exist)

This was solved by adding options.add_argument("--remote-debugging-port=9230") to the ChromeOptions(). And the program runs once and I gained the same error message as above:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created from disconnected: unable to connect to renderer (Session info: headless chrome=89.0.4389.114)

The problem here was that the chrome process does not close properly in the program so the process is still active on the debugging-port. To solve this problem close the active port sudo kill -9 $(sudo lsof -t -i:9230) and simply add the following lines to the end of the code:

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

Since I didn't find this answer anywhere, I hope it helps someone.

like image 28
Sebastian Avatar answered Oct 21 '22 06:10

Sebastian