[🐛 Bug]: SessionNotCreatedException When Instantiating ChromeDriver In Selenium (ChromeDriver 136.0.7103.93)
[🐛 Bug]: SessionNotCreatedException when instantiating ChromeDriver in Selenium (ChromeDriver 136.0.7103.93)
In this article, we will discuss a bug that has been encountered when using Selenium with ChromeDriver version 136.0.7103.93. The bug results in a SessionNotCreatedException
being thrown when attempting to instantiate the ChromeDriver. This issue has been reported to be specific to ChromeDriver version 136.x and has been confirmed to work with previous versions.
The issue at hand is a SessionNotCreatedException
that is thrown when attempting to instantiate the ChromeDriver using Selenium. This exception is typically thrown when the ChromeDriver is unable to create a new session, which in this case is due to an issue with the ChromeDriver itself.
To reproduce this issue, follow these steps:
- Install Selenium and ChromeDriver: Ensure that Selenium and ChromeDriver are installed on your system. You can install them using pip and the ChromeDriver installer, respectively.
- Update ChromeDriver to version 136.0.7103.93: Update ChromeDriver to version 136.0.7103.93, which is the version that is causing the issue.
- Run the code: Run the code that is provided below, which attempts to instantiate the ChromeDriver using Selenium.
The code that is provided below is a Python function that attempts to instantiate the ChromeDriver using Selenium. This code is similar to the code that is used in the Selenium documentation.
import socketserver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def start_chrome_and_attach() -> webdriver.Chrome:
"""Start Chrome in remote debugging mode and attaches a selenium driver.
Useful for using selenium on the default browser.
"""
with socketserver.TCPServer(("localhost", 0), None) as s:
free_port = s.server_address[1]
service = Service(_get_chrome_executable())
chrome_options = Options()
# Set the proxy for downloading the webdriver
# https://github.com/SeleniumHQ/selenium/issues/11294#issuecomment-1684143026
proxy = Proxy({"proxyType": ProxyType.MANUAL})
proxy.http_proxy = Constants.Proxies.proxies["http"]
proxy.ssl_proxy = Constants.Proxies.proxies["https"]
chrome_options.proxy = proxy
chrome_options.add_experimental_option("debuggerAddress", f"localhost:{free_port}")
chrome_options.add_argument("--disable-features=ChromeWhatsNewUI")
chrome_webdriver = webdriver.Chrome(service=service, options=chrome_options)
return chrome_webdriver
The debugging logs that are provided below are the logs that are generated when the code is run and the SessionNotCreatedException
is thrown.
automation_framework\browser_automation\system_web_browser.py:106: in get_link_url
driver = start_chrome_and_attach()
automation_framework\browser_automation_web_browser.py:94: in start_chrome_and_attach
chrome_webdriver = webdriver.Chrome(service=service, options=chrome_options)
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\chrome\webdriver.py:45: in __init__
super().__init__(
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\chromium\webdriver.py:56: in __init__
super().__init__(
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\remote\webdriver.py:207: in __init__
self.start_session(capabilities)
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\remote\webdriver.py:291: in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\remote\webdriver.py:346: in execute
self.error_handler.check_response(response)
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\remote\errorhandler.py:229: in check_response
raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.SessionNotCreatedException: Message: session not created: cannot connect to chrome at localhost:57731
E from chrome not reachable
E Stacktrace:
E GetHandleVerifier [0x00007FF7FA69A145+76773]
E GetHandleVerifier [0x00007FF7FA69A1A0+76864]
E (No symbol) [0x00007FF7FA458DAC]
E (No symbol) [0x00007FF7FA449BE1]
E (No symbol) [0x00007FF7FA49C082]
E (No symbol) [0x00007FF7FA49126E]
E (No symbol) [0x00007FF7FA4E5155]
E (No symbol) [0x00007FF7FA4E4710]
E (No symbol) [0x00007FF7FA4D7133]
E (No symbol) [0x00007FF7FA4A04D1]
E (No symbol) [0x00007FF7FA4A1263]
E GetHandleVerifier [0x00007FF7FA95A8ED+2962317]
E GetHandleVerifier [0x00007FF7FA954EC2+2939234]
E GetHandleVerifier [0x00007FF7FA972FF3+3062419]
E GetHandleVerifier [0x00007FF7FA6B4B9A+185914]
E GetHandleVerifier [0x00007FF7FA6BC78F+217647]
E GetHandleVerifier [0x00007FF7FA6A2A44+111844]
E GetHandleVerifier [0x00007FF7FA6A2BF2+112274]
E GetHandleVerifier [0x00007FF7FA688A79+5401]
E BaseThreadInitThunk [0x000FFCD0E8259D+29]
E RtlUserThreadStart [0x00007FFCD218AF38+40]
In conclusion, the SessionNotCreatedException
that is thrown when attempting to instantiate the ChromeDriver using Selenium is a bug that is specific to ChromeDriver version 136.x. This issue has been confirmed to work with previous versions of ChromeDriver. The code that is provided above is a reproducible example of this issue and can be used to test and debug the problem.
One possible workaround for this issue is to use a previous version of ChromeDriver, such as version 135.x. This will ensure that the ChromeDriver is compatible with Selenium and will not throw the SessionNotCreatedException
.
In the future, it would be beneficial to investigate the cause of this issue and to provide a fix for the ChromeDriver. This would ensure that the ChromeDriver is compatible with Selenium and will not throw the SessionNotCreatedException
.
- Selenium Documentation
- ChromeDriver Documentation
- Stack Overflow
Q&A: [🐛 Bug]: SessionNotCreatedException when instantiating ChromeDriver in Selenium (ChromeDriver 136.0.7103.93)
A: The SessionNotCreatedException is an exception that is thrown by Selenium when it is unable to create a new session with the ChromeDriver. This exception is typically thrown when the ChromeDriver is unable to connect to the Chrome browser.
A: The SessionNotCreatedException is caused by an issue with the ChromeDriver itself. Specifically, it is caused by a change in the ChromeDriver version 136.x that prevents it from connecting to the Chrome browser.
A: To reproduce the SessionNotCreatedException, follow these steps:
- Install Selenium and ChromeDriver on your system.
- Update ChromeDriver to version 136.0.7103.93.
- Run the code that is provided above, which attempts to instantiate the ChromeDriver using Selenium.
A: The reproducible code is a Python function that attempts to instantiate the ChromeDriver using Selenium. This code is similar to the code that is used in the Selenium documentation.
import socketserver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def start_chrome_and_attach() -> webdriver.Chrome:
"""Start Chrome in remote debugging mode and attaches a selenium driver.
Useful for using selenium on the default browser.
"""
with socketserver.TCPServer(("localhost", 0), None) as s:
free_port = s.server_address[1]
service = Service(_get_chrome_executable())
chrome_options = Options()
# Set the proxy for downloading the webdriver
# https://github.com/SeleniumHQ/selenium/issues/11294#issuecomment-1684143026
proxy = Proxy({"proxyType": ProxyType.MANUAL})
proxy.http_proxy = Constants.Proxies.proxies["http"]
proxy.ssl_proxy = Constants.Proxies.proxies["https"]
chrome_options.proxy = proxy
chrome_options.add_experimental_option("debuggerAddress", f"localhost:{free_port}")
chrome_options.add_argument("--disable-features=ChromeWhatsNewUI")
chrome_webdriver = webdriver.Chrome(service=service, options=chrome_options)
return chrome_webdriver
A: The debugging logs are the logs that are generated when the code is run and the SessionNotCreatedException is thrown. These logs provide information about the error and can be used to debug the issue.
automation_framework\browser_automation\system_web_browser.py:106: in get_link_url
driver = start_chrome_and_attach()
automation_framework\browser_automation\web_browser.py:94: in start_chrome_and_attach
chrome_webdriver = webdriver.Chrome(service=service, options=chrome_options)
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\chrome\webdriver.py:45: in __init__
super().__init__(
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\chromium\webdriver.py:56: in __init__
super().__init__(
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\remote\webdriver.py:207: in __init__
self.start_session(capabilities)
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\remote\webdriver.py:291: in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\remote\webdriver.py:346: in execute
self.error_handler.check_response(response)
C:\Users\acs\.virtualenvs\UITest-S2COC7wJ\Lib\site-packages\selenium\webdriver\remote\errorhandler.py:229: in check_response
raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.SessionNotCreatedException: Message: session not created: cannot connect to chrome at localhost:57731
E from chrome not reachable
E Stacktrace:
E GetHandleVerifier [0x00007FF7FA69A145+76773]
E GetHandleVerifier [0x00007FF7FA69A1A0+76864]
E (No symbol) [0x00007FF7FA458DAC]
E (No symbol) [0x00007FF7FA449BE1]
E (No symbol) [0x00007FF7FA49C082]
E (No symbol) [0x00007FF7FA49126E]
E (No symbol) [0x00007FF7FA4E5155]
E (No symbol) [0x00007FF7FA4E4710]
E (No symbol) [0x00007FF7FA4D7133]
E (No symbol) [0x00007FF7FA4A04D1]
E (No symbol) [0x00007FF7FA4A1263]
E GetHandleVerifier [0x00007FF7FA95A8ED+2962317]
E GetHandleVerifier [0x00007FF7FA954EC2+2939234]
E GetHandleVerifier [0x00007FF7FA972FF3+3062419]
E GetHandleVerifier [0x00007FF7FA6B4B9A+185914]
E GetHandleVerifier [0x00007FF7FA6BC78F+217647]
E GetHandleVerifier [0x00007FF7FA6A2A44+111844]
E GetHandleVerifier [0x00007FF7FA6A2BF2+112274]
E GetHandleVerifier [0x00007FF7FA688A79+5401]
E BaseThreadInitThunk [0x000FFCD0E8259D+29]
E RtlUserThreadStart [0x00007FFCD218AF38+40]
A: One possible workaround for this issue is to use a previous version of ChromeDriver, such as version 135.x. This will ensure that the ChromeDriver is compatible with Selenium and will not throw the SessionNotCreatedException.
A: In the future, it would be beneficial to investigate the cause of this issue and to provide a fix for the ChromeDriver. This would ensure that the ChromeDriver is compatible with Selenium and will not throw the SessionNotCreatedException.