Skip to content

Commit

Permalink
[py] Updated Handling for DetachedShadowRoot Exception (#14677)
Browse files Browse the repository at this point in the history
  • Loading branch information
shbenzer authored Nov 8, 2024
1 parent 7257cf3 commit 7aabb8d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions py/selenium/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from .exceptions import DetachedShadowRootException
from .exceptions import ElementClickInterceptedException
from .exceptions import ElementNotInteractableException
from .exceptions import ElementNotSelectableException
Expand Down Expand Up @@ -83,4 +84,5 @@
"InvalidSessionIdException",
"SessionNotCreatedException",
"UnknownMethodException",
"DetachedShadowRootException",
]
4 changes: 4 additions & 0 deletions py/selenium/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,7 @@ 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 @@ -19,6 +19,7 @@
from typing import Dict
from typing import Type

from selenium.common.exceptions import DetachedShadowRootException
from selenium.common.exceptions import ElementClickInterceptedException
from selenium.common.exceptions import ElementNotInteractableException
from selenium.common.exceptions import ElementNotSelectableException
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
6 changes: 6 additions & 0 deletions py/test/unit/selenium/webdriver/remote/error_handler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ def test_raises_exception_for_method_not_allowed(handler, code):
handler.check_response({"status": code, "value": "foo"})


@pytest.mark.parametrize("code", ErrorCode.DETACHED_SHADOW_ROOT)
def test_raises_exception_for_detached_shadow_root(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):
import json
Expand Down

0 comments on commit 7aabb8d

Please sign in to comment.