Skip to content

Commit 7aabb8d

Browse files
authored
[py] Updated Handling for DetachedShadowRoot Exception (SeleniumHQ#14677)
1 parent 7257cf3 commit 7aabb8d

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

py/selenium/common/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
from .exceptions import DetachedShadowRootException
1819
from .exceptions import ElementClickInterceptedException
1920
from .exceptions import ElementNotInteractableException
2021
from .exceptions import ElementNotSelectableException
@@ -83,4 +84,5 @@
8384
"InvalidSessionIdException",
8485
"SessionNotCreatedException",
8586
"UnknownMethodException",
87+
"DetachedShadowRootException",
8688
]

py/selenium/common/exceptions.py

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

287287
super().__init__(with_support, screen, stacktrace)
288+
289+
290+
class DetachedShadowRootException(WebDriverException):
291+
"""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
@@ -19,6 +19,7 @@
1919
from typing import Dict
2020
from typing import Type
2121

22+
from selenium.common.exceptions import DetachedShadowRootException
2223
from selenium.common.exceptions import ElementClickInterceptedException
2324
from selenium.common.exceptions import ElementNotInteractableException
2425
from selenium.common.exceptions import ElementNotSelectableException
@@ -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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ def test_raises_exception_for_method_not_allowed(handler, code):
242242
handler.check_response({"status": code, "value": "foo"})
243243

244244

245+
@pytest.mark.parametrize("code", ErrorCode.DETACHED_SHADOW_ROOT)
246+
def test_raises_exception_for_detached_shadow_root(handler, code):
247+
with pytest.raises(exceptions.DetachedShadowRootException):
248+
handler.check_response({"status": code, "value": "foo"})
249+
250+
245251
@pytest.mark.parametrize("key", ["stackTrace", "stacktrace"])
246252
def test_relays_exception_stacktrace(handler, key):
247253
import json

0 commit comments

Comments
 (0)