Skip to content

Commit 75a0efa

Browse files
committed
[py] Add DetachedShadowRoot Exception
1 parent f391cd0 commit 75a0efa

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

py/selenium/common/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from .exceptions import UnexpectedTagNameException
4949
from .exceptions import UnknownMethodException
5050
from .exceptions import WebDriverException
51+
from .exceptions import DetachedShadowRootException
5152

5253
__all__ = [
5354
"WebDriverException",
@@ -83,4 +84,5 @@
8384
"InvalidSessionIdException",
8485
"SessionNotCreatedException",
8586
"UnknownMethodException",
87+
"DetachedShadowRootException"
8688
]

py/selenium/common/exceptions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,6 @@ def __init__(
285285
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}/driver_location"
286286

287287
super().__init__(with_support, screen, stacktrace)
288+
289+
class DetachedShadowRootException(WebDriverException):
290+
"""Raised when referenced shadow root is no longer attached to the DOM"""

py/selenium/webdriver/remote/errorhandler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from selenium.common.exceptions import ElementNotInteractableException
2424
from selenium.common.exceptions import ElementNotSelectableException
2525
from selenium.common.exceptions import ElementNotVisibleException
26+
from selenium.common.exceptions import DetachedShadowRootException
2627
from selenium.common.exceptions import ImeActivationFailedException
2728
from selenium.common.exceptions import ImeNotAvailableException
2829
from selenium.common.exceptions import InsecureCertificateException
@@ -88,6 +89,7 @@ class ExceptionMapping:
8889
UNABLE_TO_CAPTURE_SCREEN = ScreenshotException
8990
ELEMENT_CLICK_INTERCEPTED = ElementClickInterceptedException
9091
UNKNOWN_METHOD = UnknownMethodException
92+
DETACHED_SHADOW_ROOT = DetachedShadowRootException
9193

9294

9395
class ErrorCode:
@@ -131,6 +133,7 @@ class ErrorCode:
131133
UNABLE_TO_CAPTURE_SCREEN = [63, "unable to capture screen"]
132134
ELEMENT_CLICK_INTERCEPTED = [64, "element click intercepted"]
133135
UNKNOWN_METHOD = ["unknown method exception"]
136+
DETACHED_SHADOW_ROOT = [65,"detached shadow root"]
134137

135138
METHOD_NOT_ALLOWED = [405, "unsupported operation"]
136139

py/test/unit/selenium/webdriver/remote/error_handler_tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ def test_raises_exception_for_unknown_method(handler, code):
240240
def test_raises_exception_for_method_not_allowed(handler, code):
241241
with pytest.raises(exceptions.WebDriverException):
242242
handler.check_response({"status": code, "value": "foo"})
243-
243+
244+
@pytest.mark.parametrize("code", ErrorCode.DETACHED_SHADOW_ROOT)
245+
def test_raises_exception_for_invalid_selector(handler, code):
246+
with pytest.raises(exceptions.DetachedShadowRootException):
247+
handler.check_response({"status": code, "value": "foo"})
244248

245249
@pytest.mark.parametrize("key", ["stackTrace", "stacktrace"])
246250
def test_relays_exception_stacktrace(handler, key):

0 commit comments

Comments
 (0)