Skip to content

fix: map 'detached shadow root' to DetachedShadowRootException - #9

Draft
MattL1989 wants to merge 1 commit into
masterfrom
fix/detached-shadow-root-exception
Draft

MattL1989 wants to merge 1 commit into
masterfrom
fix/detached-shadow-root-exception

Conversation

@MattL1989

Copy link
Copy Markdown
Owner

Problem

ERROR_TO_EXC_MAPPING in appium/webdriver/errorhandler.py maps the W3C detached shadow root error to NoSuchShadowRootException. Selenium maps it to DetachedShadowRootException. The two classes are unrelated (both subclass WebDriverException directly), so with the Appium client except DetachedShadowRootException never fires:

response = {
    'status': 404,
    'value': json.dumps({'value': {'error': 'detached shadow root', 'message': 'detached shadow root'}}),
}
MobileErrorHandler().check_response(response)
# raises NoSuchShadowRootException; Selenium raises DetachedShadowRootException

A server returns this error, for example in a webview context, when a test uses a shadow root after the page removed it from the DOM.

Fix

Map 'detached shadow root' to selenium.common.exceptions.DetachedShadowRootException. This is a one-line change.

Behaviour change: code that catches NoSuchShadowRootException to handle a detached shadow root needs to catch DetachedShadowRootException instead, or both. Code catching WebDriverException is not affected.

Tests

  • New test/unit/webdriver/errorhandler_shadow_root_test.py checks that:
    • a detached shadow root error raises DetachedShadowRootException;
    • a no such shadow root error still raises NoSuchShadowRootException.
  • The first test fails without the fix: NoSuchShadowRootException: Message: detached shadow root is raised instead.
  • ruff check, ruff format --check, mypy appium and the full unit test suite pass.

🤖 Generated with Claude Code

ERROR_TO_EXC_MAPPING mapped the W3C `detached shadow root` error to
NoSuchShadowRootException. Selenium maps it to
DetachedShadowRootException, which is not a subclass of
NoSuchShadowRootException, so `except DetachedShadowRootException`
never caught the error when using the Appium client.

Map it to selenium's DetachedShadowRootException.

Behaviour change: code that caught NoSuchShadowRootException for a
detached shadow root needs to catch DetachedShadowRootException (or
WebDriverException) instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant