geckodriver
geckodriver copied to clipboard
Execute script should return Shadow Root object
System
- Version: 0.31
- Platform: macOS Big Sur
- Firefox: 99.0.1 (64-bit
- Selenium: Ruby 4.1.0
Testcase
https://github.com/SeleniumHQ/selenium/blob/trunk/common/src/web/webComponents.html
custom_element = driver.find_element(css: 'custom-checkbox-element')
driver.execute_script('return arguments[0].shadowRoot;', custom_element)
Stacktrace
Selenium::WebDriver::Error::UnknownError:
TypeError: can't access property "documentElement", node.ownerDocument is null
# element.isInXULDocument@chrome://remote/content/marionette/element.js:1353:1
# from@chrome://remote/content/marionette/element.js:1497:19
# element.getElementId@chrome://remote/content/marionette/element.js:624:28
# evaluate.toJSON@chrome://remote/content/marionette/evaluate.js:348:20
# evaluate.toJSON@chrome://remote/content/marionette/evaluate.js:362:27
# receiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:177:31
Trace-level log
2022-04-13 11:06:30 INFO Selenium -> POST session/fc8da6b9-d389-4135-b989-7bdc9b823ab8/execute/sync
2022-04-13 11:06:30 INFO Selenium >>> http://127.0.0.1:4444/session/fc8da6b9-d389-4135-b989-7bdc9b823ab8/execute/sync | {"script":"return arguments[0].shadowRoot;","args":[{"element-6066-11e4-a52e-4f735466cecf":"958ad183-5852-40d6-aafb-de385a0facd8"}]}
2022-04-13 11:06:30 DEBUG Selenium > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"selenium/4.1.0 (ruby macosx)", "Content-Length"=>"132"}
1649865990830 webdriver::server DEBUG -> POST /session/fc8da6b9-d389-4135-b989-7bdc9b823ab8/execute/sync {"script":"return arguments[0].shadowRoot;","args":[{"element-6066-11e4-a52e-4f735466cecf":"958ad183-5852-40d6-aafb-de385a0facd8"}]}
1649865990831 Marionette DEBUG 0 -> [0,12,"WebDriver:ExecuteScript",{"args":[{"element-6066-11e4-a52e-4f735466cecf":"958ad183-5852-40d6-aafb-de385a0facd8"}],"script":"return arguments[0].shadowRoot;"}]
1649865990842 Marionette DEBUG 0 <- [1,12,{"error":"unknown error","message":"TypeError: can't access property \"documentElement\", node.ownerDocument is null"," ... tte/evaluate.js:362:27\nreceiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:177:31\n"},null]
1649865990842 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"unknown error","message":"TypeError: can't access property \"documentElement\", node.ownerDocument is null","stacktrace":"element.isInXULDocument@chrome://remote/content/marionette/element.js:1353:1\nfrom@chrome://remote/content/marionette/element.js:1497:19\nelement.getElementId@chrome://remote/content/marionette/element.js:624:28\nevaluate.toJSON@chrome://remote/content/marionette/evaluate.js:348:20\nevaluate.toJSON@chrome://remote/content/marionette/evaluate.js:362:27\nreceiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:177:31\n"}}
2022-04-13 11:06:30 INFO Selenium <- {"value":{"error":"unknown error","message":"TypeError: can't access property \"documentElement\", node.ownerDocument is null","stacktrace":"element.isInXULDocument@chrome://remote/content/marionette/element.js:1353:1\nfrom@chrome://remote/content/marionette/element.js:1497:19\nelement.getElementId@chrome://remote/content/marionette/element.js:624:28\nevaluate.toJSON@chrome://remote/content/marionette/evaluate.js:348:20\nevaluate.toJSON@chrome://remote/content/marionette/evaluate.js:362:27\nreceiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:177:31\n"}}
This is known and is handled in: https://bugzilla.mozilla.org/show_bug.cgi?id=1764594.
Workaround for now is to use Execute Async Script instead.
Can you provide an example of what code I'd execute for this so I can add it to our test suite? My JS is very limited and I don't really understand execute_async_script usage or resolves. Thanks!
Related tests can be found in wpt (here from our downstream sync):
https://searchfox.org/mozilla-central/rev/4d2b1f753871ce514f9dccfc5b1b5e867f499229/testing/web-platform/tests/webdriver/tests/execute_script/node.py#40-70 https://searchfox.org/mozilla-central/rev/4d2b1f753871ce514f9dccfc5b1b5e867f499229/testing/web-platform/tests/webdriver/tests/execute_async_script/node.py#41-71
The bug is fixed now in the Firefox 111 nightly build.