Skip to content
2 changes: 2 additions & 0 deletions py/selenium/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from .exceptions import UnexpectedTagNameException
from .exceptions import UnknownMethodException
from .exceptions import WebDriverException
from .exceptions import DetachedShadowRootException

__all__ = [
"WebDriverException",
Expand Down Expand Up @@ -83,4 +84,5 @@
"InvalidSessionIdException",
"SessionNotCreatedException",
"UnknownMethodException",
"DetachedShadowRootException"
]
3 changes: 3 additions & 0 deletions py/selenium/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,6 @@ def __init__(
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}/driver_location"

super().__init__(with_support, screen, stacktrace)

class DetachedShadowRootException(WebDriverException):
"""Raised when referenced shadow root is no longer attached to the DOM"""
3 changes: 3 additions & 0 deletions py/selenium/webdriver/remote/errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from selenium.common.exceptions import ElementNotInteractableException
from selenium.common.exceptions import ElementNotSelectableException
from selenium.common.exceptions import ElementNotVisibleException
from selenium.common.exceptions import DetachedShadowRootException
from selenium.common.exceptions import ImeActivationFailedException
from selenium.common.exceptions import ImeNotAvailableException
from selenium.common.exceptions import InsecureCertificateException
Expand Down Expand Up @@ -88,6 +89,7 @@ class ExceptionMapping:
UNABLE_TO_CAPTURE_SCREEN = ScreenshotException
ELEMENT_CLICK_INTERCEPTED = ElementClickInterceptedException
UNKNOWN_METHOD = UnknownMethodException
DETACHED_SHADOW_ROOT = DetachedShadowRootException


class ErrorCode:
Expand Down Expand Up @@ -131,6 +133,7 @@ class ErrorCode:
UNABLE_TO_CAPTURE_SCREEN = [63, "unable to capture screen"]
ELEMENT_CLICK_INTERCEPTED = [64, "element click intercepted"]
UNKNOWN_METHOD = ["unknown method exception"]
DETACHED_SHADOW_ROOT = [65,"detached shadow root"]

METHOD_NOT_ALLOWED = [405, "unsupported operation"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ def test_raises_exception_for_unknown_method(handler, code):
def test_raises_exception_for_method_not_allowed(handler, code):
with pytest.raises(exceptions.WebDriverException):
handler.check_response({"status": code, "value": "foo"})


@pytest.mark.parametrize("code", ErrorCode.DETACHED_SHADOW_ROOT)
def test_raises_exception_for_invalid_selector(handler, code):
with pytest.raises(exceptions.DetachedShadowRootException):
handler.check_response({"status": code, "value": "foo"})

@pytest.mark.parametrize("key", ["stackTrace", "stacktrace"])
def test_relays_exception_stacktrace(handler, key):
Expand Down
Loading