Skip to content

Fix: resolve W3C element references in execute/sync and execute/async#3

Open
FumblingBarbell wants to merge 1 commit into
danielraffel:mainfrom
FumblingBarbell:fix/resolve-element-refs-in-execute-sync
Open

Fix: resolve W3C element references in execute/sync and execute/async#3
FumblingBarbell wants to merge 1 commit into
danielraffel:mainfrom
FumblingBarbell:fix/resolve-element-refs-in-execute-sync

Conversation

@FumblingBarbell
Copy link
Copy Markdown

Summary

  • Fixes execute/sync and execute/async handlers to resolve W3C element references ({"element-6066-11e4-a52e-4f735466cecf": "<uuid>"}) to real DOM nodes before passing them to script execution
  • The perform_actions handler already did this; execute_sync and execute_async did not
  • This caused every WebdriverIO command that internally uses browser.execute(script, element) to fail — including isDisplayed(), waitForDisplayed(), checkVisibility(), etc.

How it works

  1. CLI (tauri-wd): New resolve_script_args() function recursively walks the args array and replaces W3C element reference objects with {"__wd_resolve": {"selector": "...", "index": N, "using": "..."}} markers
  2. Plugin: New RESOLVE_ARGS_JS JavaScript preamble injected into script_execute and script_execute_async that resolves __wd_resolve markers to real DOM nodes via document.querySelectorAll() (CSS) or document.evaluate() (XPath)

Error before fix

WebDriverError: Argument 1 ('other') to Node.contains must be an instance of Node
when running "execute/sync" with method "POST"

Test plan

  • Added regression tests in tests/wdio/specs/script.spec.mjs:
    • Element ref passed to sync browser.execute()
    • Element ref passed to async browser.executeAsync()
    • isDisplayed() on an element (the original failing case)
  • cargo check passes

Fixes #2

When WebdriverIO calls browser.execute(script, element), it serializes the
element as a W3C element reference object. Per the W3C WebDriver spec, the
server must deserialize this back to a real DOM node before injecting it
into the script. The perform_actions handler already does this, but
execute_sync and execute_async did not, causing every element-based script
execution to fail with "Argument 1 ('other') to Node.contains must be an
instance of Node".

Changes:
- CLI (tauri-wd): Add resolve_script_args() that recursively walks the args
  array and replaces W3C element references with __wd_resolve markers
  containing selector/index/using info.
- Plugin: Add RESOLVE_ARGS_JS constant — a JavaScript preamble injected into
  script_execute and script_execute_async that resolves __wd_resolve markers
  back to real DOM nodes via querySelectorAll or XPath evaluate.
- Tests: Add regression tests for element refs in sync/async scripts and
  isDisplayed().

Fixes danielraffel#2

Co-Authored-By: Claude Opus 4.6 <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.

execute/sync does not resolve W3C element references to DOM nodes

1 participant