-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[🐛 Bug]: Unable to access shadow root via Selenium #15665
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
Comments
@GaurangTandon, thank you for creating this issue. We will troubleshoot it as soon as we can. Selenium Triage Team: remember to follow the Triage Guide |
Shadow roots can either be in 'open' or 'closed' states. Selenium requires JavaScript to access shadow roots in the closed state. The following works for me: driver = webdriver.Chrome()
driver.get('https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000QLJIySAP')
element = driver.find_element(By.CSS_SELECTOR, 'TBC-FEED-ITEM-DETAIL-PAGE')
root = driver.execute_script("return arguments[0].shadowRoot", element)
child = root.find_element(By.CSS_SELECTOR, 'TBC-FEED-V2') |
@shbenzer what is the action you want to take on this? |
@titusfortner I was originally waiting for a response from the creator, but I think it can be closed on reflection. |
Hi @shbenzer Thanks for the response. To be clear, closed shadow roots are directly accessible in Selenium since version 131 of ChromeDriver. I myself use it in other test files (ChromeDriver commit) I found a possible reason after some more debugging. The Trailblazer site has its custom implementation of attachShadow: attachShadow: {
value: function(e) {
return e["$$lwc-synthetic-mode"] ? Xn(this, e) : we.call(this, e)
// ^^^^^^^^^^^---- I confirmed this branch is triggered
},
enumerable: !0,
writable: !0,
configurable: !0
}, which is from their Synthetic Shadow DOM polyfill So, the Either way it seems this is not an issue with Selenium. I will leave this post up as reference for future readers (who may also find this behavior confusing) |
Very cool! Thanks for letting us know |
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs. |
Uh oh!
There was an error while loading. Please reload this page.
Description
Steps to repro issue:
document.querySelector('TBC-FEED-ITEM-DETAIL-PAGE').shadowRoot.querySelector('TBC-FEED-V2')
python file.py
Actual
The script fails to find the shadow root that we were able to find using JavaScript above.
Expected
The script will be able to find the shadow root.
Stacktrace
Reproducible Code
Debugging Logs
The text was updated successfully, but these errors were encountered: