Skip to content

Commit 1648fb9

Browse files
committed
[py] Call service.stop() when session can't be started
1 parent 8c9aa17 commit 1648fb9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

py/selenium/webdriver/remote/webdriver.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from selenium.common.exceptions import JavascriptException
4141
from selenium.common.exceptions import NoSuchCookieException
4242
from selenium.common.exceptions import NoSuchElementException
43+
from selenium.common.exceptions import SessionNotCreatedException
4344
from selenium.common.exceptions import WebDriverException
4445
from selenium.webdriver.common.bidi.browser import Browser
4546
from selenium.webdriver.common.bidi.network import Network
@@ -343,9 +344,13 @@ def start_session(self, capabilities: dict) -> None:
343344
"""
344345

345346
caps = _create_caps(capabilities)
346-
response = self.execute(Command.NEW_SESSION, caps)["value"]
347-
self.session_id = response.get("sessionId")
348-
self.caps = response.get("capabilities")
347+
try:
348+
response = self.execute(Command.NEW_SESSION, caps)["value"]
349+
self.session_id = response.get("sessionId")
350+
self.caps = response.get("capabilities")
351+
except SessionNotCreatedException:
352+
self.service.stop()
353+
raise
349354

350355
def _wrap_value(self, value):
351356
if isinstance(value, dict):

0 commit comments

Comments
 (0)