Fix: resolve W3C element references in execute/sync and execute/async#3
Open
FumblingBarbell wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
execute/syncandexecute/asynchandlers to resolve W3C element references ({"element-6066-11e4-a52e-4f735466cecf": "<uuid>"}) to real DOM nodes before passing them to script executionperform_actionshandler already did this;execute_syncandexecute_asyncdid notbrowser.execute(script, element)to fail — includingisDisplayed(),waitForDisplayed(),checkVisibility(), etc.How it works
tauri-wd): Newresolve_script_args()function recursively walks theargsarray and replaces W3C element reference objects with{"__wd_resolve": {"selector": "...", "index": N, "using": "..."}}markersRESOLVE_ARGS_JSJavaScript preamble injected intoscript_executeandscript_execute_asyncthat resolves__wd_resolvemarkers to real DOM nodes viadocument.querySelectorAll()(CSS) ordocument.evaluate()(XPath)Error before fix
Test plan
tests/wdio/specs/script.spec.mjs:browser.execute()browser.executeAsync()isDisplayed()on an element (the original failing case)cargo checkpassesFixes #2