Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py] Updated Handling for DetachedShadowRoot Exception #14677

Merged
merged 10 commits into from
Nov 8, 2024
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
Loading