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

Returning shadowRoot element fails with "cyclic object value" error #1711

Closed
juchen33 opened this issue Apr 15, 2020 · 18 comments
Closed

Returning shadowRoot element fails with "cyclic object value" error #1711

juchen33 opened this issue Apr 15, 2020 · 18 comments

Comments

@juchen33
Copy link

Even if this is not defined in WebDriver Spec, It is working completely fine with Latest Firefox (V67) and Geckodriver (V0.24).

Please find linked screenshot as proof.

@blackgrouse just need to write case as below

IWebElement finalElement = (IWebElement)((IJavaScriptExecutor)_driver).ExecuteScript("return document.querySelector(\"shop-app\").shadowRoot.querySelector(\"shop-home\").shadowRoot.querySelector(\"div.item > shop-button\"));

You will get your element directly without even iterating

Originally posted by @rudreshtrivedi in #1428 (comment)

@juchen33 juchen33 changed the title Even if this is not defined in WebDriver Spec, It is working completely fine with Latest Firefox (V67) and Geckodriver (V0.24). Open shadow root DOM failed with Cyclic object value Error in Firefox 68.7.0 ESR Apr 15, 2020
@juchen33
Copy link
Author

juchen33 commented Apr 15, 2020

It has been mentioned in the other closed issue that this issue may have been fixed since Firefox 67.
But It was reproduced with Firefox 68.7.0 ESR

Geckodriver v0.26.0
Firefox v68.7.0 ESR
Selenium v3.141
Windows 10

In Java,
WebElement shadow = (WebElement) ((JavascriptExecutor) driver).executeScript("return arguments[0].shadowRoot",element);

org.openqa.selenium.JavascriptException: Cyclic object value
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host:os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 68.7.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20200403171148, moz:geckodriverVersion: 0.26.0, moz:headless: false, moz:processID: 14260, moz:profile: moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}

Trace Level Logs

1587018137805 webdriver::server DEBUG -> POST /session/fc2105f3-0b19-4f0c-8715-978cbf9ee5e4/execute/sync {
"script": "return arguments[0].shadowRoot",
"args": [
{
"ELEMENT": "2fe9af88-d3b0-450e-9277-4352a3ff21ff",
"element-6066-11e4-a52e-4f735466cecf": "2fe9af88-d3b0-450e-9277-4352a3ff21ff"
}
]
}
1587018137807 Marionette DEBUG 0 -> [0,713,"WebDriver:ExecuteScript",{"args":[{"ELEMENT":"2fe9af88-d3b0-450e-9277-4352a3ff21ff","element-6066-11e4-a52e-4f735466cecf":"2fe9af88-d3b0-450e-9277-4352a3ff21ff"}],"script":"return arguments[0].shadowRoot"}]
1587018137816 Marionette DEBUG 0 <- [1,713,{"error":"javascript error","message":"Cyclic object value","stacktrace":"WebDriverError@chrome://marionette/content/e ... esponse@chrome://marionette/content/listener.js:700:26\ndispatch/</<@chrome://marionette/content/listener.js:536:19\n"},null]
1587018137815 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"javascript error","message":"Cyclic object value","stacktrace":"WebDriverError@chrome://marionette/content/error.js:175:5\nJavaScriptError@chrome://marionette/content/error.js:354:5\nassert.acyclic@chrome://marionette/content/assert.js:61:11\nevaluate.toJSON@chrome://marionette/content/evaluate.js:301:12\nsendResponse@chrome://marionette/content/listener.js:700:26\ndispatch/</<@chrome://marionette/content/listener.js:536:19\n"}}

@whimboo
Copy link
Collaborator

whimboo commented Apr 16, 2020

Could you please attach a trace-level log from geckodriver? Read more about reporting actionable bugs in our contribution guidelines.

@juchen33
Copy link
Author

juchen33 commented Apr 16, 2020 via email

@juchen33
Copy link
Author

Could you please attach a trace-level log from geckodriver? Read more about reporting actionable bugs in our contribution guidelines.

Trace Level Logs

1587018137805 webdriver::server DEBUG -> POST /session/fc2105f3-0b19-4f0c-8715-978cbf9ee5e4/execute/sync {
"script": "return arguments[0].shadowRoot",
"args": [
{
"ELEMENT": "2fe9af88-d3b0-450e-9277-4352a3ff21ff",
"element-6066-11e4-a52e-4f735466cecf": "2fe9af88-d3b0-450e-9277-4352a3ff21ff"
}
]
}
1587018137807 Marionette DEBUG 0 -> [0,713,"WebDriver:ExecuteScript",{"args":[{"ELEMENT":"2fe9af88-d3b0-450e-9277-4352a3ff21ff","element-6066-11e4-a52e-4f735466cecf":"2fe9af88-d3b0-450e-9277-4352a3ff21ff"}],"script":"return arguments[0].shadowRoot"}]
1587018137816 Marionette DEBUG 0 <- [1,713,{"error":"javascript error","message":"Cyclic object value","stacktrace":"WebDriverError@chrome://marionette/content/e ... esponse@chrome://marionette/content/listener.js:700:26\ndispatch/</<@chrome://marionette/content/listener.js:536:19\n"},null]
1587018137815 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"javascript error","message":"Cyclic object value","stacktrace":"WebDriverError@chrome://marionette/content/error.js:175:5\nJavaScriptError@chrome://marionette/content/error.js:354:5\nassert.acyclic@chrome://marionette/content/assert.js:61:11\nevaluate.toJSON@chrome://marionette/content/evaluate.js:301:12\nsendResponse@chrome://marionette/content/listener.js:700:26\ndispatch/</<@chrome://marionette/content/listener.js:536:19\n"}}

@whimboo
Copy link
Collaborator

whimboo commented Apr 17, 2020

Thanks. Now I noticed that there is already https://bugzilla.mozilla.org/show_bug.cgi?id=1489490 for specifically this problem.

Also the WebDriver spec needs to be updated. See: w3c/webdriver#350

@whimboo whimboo changed the title Open shadow root DOM failed with Cyclic object value Error in Firefox 68.7.0 ESR Returning shadowRoot element fails with "cyclic object value" error Apr 17, 2020
@juchen33
Copy link
Author

juchen33 commented Apr 17, 2020 via email

@Baiskey

This comment has been minimized.

@alagappan-annamalai

This comment has been minimized.

@Trooper13

This comment has been minimized.

@ZaiweiXiong

This comment has been minimized.

@whimboo
Copy link
Collaborator

whimboo commented Aug 13, 2020

Everyone please stop posting "me too" comments on this issue. As you can notice by #1711 (comment) we are aware of this problem, which hasn't been fixed yet. Thanks.

@CAVAh
Copy link

CAVAh commented Sep 9, 2020

Using return arguments[0].shadowRoot.children instead return arguments[0].shadowRoot on executeScript() works for me. Doesn't throw an error, will result a list of FirefoxWebElement, but you can select one of the list (in my case the last one). Not a fix, but as a work around..

@whimboo
Copy link
Collaborator

whimboo commented Jul 13, 2022

Please note that there is no need anymore to use script execution for retrieving the shadow root element given that all the recent Selenium bindings should actually support the Get Element Shadow Root command command and Firefox since version 96 and geckodriver 0.31.0.

I'll still try to get the failure for execute script in https://bugzilla.mozilla.org/show_bug.cgi?id=1764594.

@JohnA2

This comment was marked as off-topic.

@whimboo

This comment was marked as off-topic.

@paulmillar
Copy link

@whimboo, at least for the remote driver, the shadow_root property contains an explicit check that rejects Firefox.

As far as I can see, something like:

shadow_root = driver.execute_script('return arguments[0].shadowRoot', shadow_host)

is the only way that works for all versions of Chrome.

The same approach should also work for Firefox, except for this issue.

@fenchu
Copy link

fenchu commented Apr 26, 2023

This is mostly fixed with geckodriver 0.33.0 and FF113.

instead of the script execution you can use the shadow_root:
(this refers to everything under :shadow_root in the dom)

el = WebDriverWait(wd, 10).until(EC.presence_of_element_located((By.XPATH, "//*[@id='select-type-dispensation']")))
el = el.shadow_root.find_element(By.CSS_SELECTOR, "select.bp-select")
el.click()

you cant use XPATH in shadow_root, and there are some small bugs left.

@whimboo
Copy link
Collaborator

whimboo commented Apr 26, 2023

Oh right, I should have closed this issue as fixed.

Regarding the XPATH issue this is https://bugzilla.mozilla.org/show_bug.cgi?id=1822311 and there needs to be a discussion in the WG group how we want to handle the unsupported strategy - most likely to raise a specific error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants