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
[🐛 Bug]: "Get Text" atom returns an empty string for elements within a closed ShadowDOM #13132
Comments
@whimboo, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
The problem here is actually the check for the |
I'm not sure if this makes any difference, but we've run into the same issue and I've prepared a simple demonstration project, where it can be reproduced using simple webcomponent with a |
@whimboo what makes you think its anything to do with if you're right, you're saying firefox doesn't implement just trying to figure out how you got to where you are, and see if i can help its been a while but tldr is that we very simply just iterate over the children, and if we hit a |
So when I remove the check for the Please note that I don't have detailed knowledge yet how slots work so in case of more information I would have to dig into it myself. And Firefox supports |
yes because you will be traversing the text node as if it isn't slotted. it might be making it work but it isn't whats wrong afaict it just happens to work because you're treating the text node as a regular non-slotted node at that point which suggests the bug actually lives inside the code which traverses a slot's given this html: <some-element>
#shadow-root
<slot></slot>
#text("Some text")
</some-element> we basically do:
|
here's the logic which does that stuff: selenium/javascript/atoms/dom.js Lines 1313 to 1337 in 573eee0
its pretty old now, and tbh someone should throw away the shadow dom v0 stuff these days but i imagine if there is a bug, its somewhere in there ill see if i can reproduce it |
@whimboo can you try it on your end with i.e. this line: selenium/javascript/atoms/dom.js Lines 1411 to 1412 in 573eee0
just temporarily make it explicitly pass |
I tested with |
i did try reproduce, but am struggling: this is basically all the dom stuff copy pasted with the goog helpers replaced in the console, if you inspect the custom element and call |
@43081j that was actually a great idea to copy all the methods and remove deps for the Google modules. It's indeed passing for me as well when everything is executed from within the web page. As such I've also copied the full generated minified atom code for So that means that something actually causes trouble for us in Firefox when we run this generated atom code in privileged code. As such I'll go ahead and take the reduced code from your jsfiddle to try to find out what's actually broken on our side. Work will be continued to be tracked on https://bugzilla.mozilla.org/show_bug.cgi?id=1824664. That said it looks like that there is actually no bug in the Selenium atoms code and that we do not need to keep this issue open. Sorry for wasting your time on that issue, but on the other side also a big thank you for preparing that code that I can now easily use! |
i'm still super curious what the problem is so will be sure to track the other related issues let me know if it ultimately does come back here and is a selenium problem after all |
@43081j I have actually one more question. The stripped down code of the Note that internally we always have access to the Here a new https://jsfiddle.net/umzdhajn/ that demonstrates that behavior. |
Ok, so the problematic lines here are these: selenium/javascript/atoms/dom.js Lines 590 to 594 in 3041af3
|
with a closed shadow root, i'd expect it to treat the element as if there is no shadow root, i.e. just return the text since i.e. in your fiddle everything inside the shadow root should be treated as if it doesn't exist (since normally we can't access a closed shadow root) |
But that's not how it works right now. Because of the above check it is marked as not being displayed (shown) and returns an empty string. I wonder if the above check should only be executed when |
is that because in your case do you know how we managed to get to an element inside that root in the first place? you're probably right, just trying to get my head around how we're dealing with closed roots since i thought they wouldn't even be traversed, so wouldn't reach that point |
See the new fiddle for the workaround in how to get into a closed shadow root. With that you can retrieve the element and call the atom on. In Firefox we won't need such a workaround given that for privileged code we have a |
While this check may have side-effects it at least would give code a chance to retrieve the visible text at all from the element. If there is agreement I could at least create a PR and try to get a test written as well for it. |
ah interesting, so you expose the closed root as a property on your components yeah for sure thats what'll be tripping things up since really you want a way to define how it should get the shadow root i think. i.e. a way to say "anytime you try access shadowRoot, actually use |
Sadly Let me re-phrase the summary of the issue and maybe @shs96c and @AutomatedTester have some further input as well. |
I've patched our internal usage of the atom and a try build shows no failures anymore for all the wdspec tests that cover closed Shadow DOMs. Also no browser at the moment works for closed Shadow DOM. For Firefox some show green because we run the atoms in privileged scope where we always have access to |
yeah im not sure how we could safely update the code over here 🤔 since the behaviour you want is only possible because you have a special environment where so if we wanted the code here to do what you want, i think it'd need to allow you to customise it rather than removing/changing that check for everyone |
Please note that the WebDriver classic specification that is used by all browsers to retrieve the visible text relies on a given revision of the atoms. So it's not that we can customize it for our own needs. But what would be bad on the extra |
just reading through it properly now, i think it should actually be this: if (parent.host.shadowRoot && parent.host.shadowRoot !== parent) {
// There is a younger shadow root, which will take precedence over
// the shadow this element is in, thus this element won't be
// displayed.
return false; i.e. the extra its been years but from what i understand, this condition is in case you're somehow in a shadow root which is no longer the shadow root (how you get to that state, i dont remember... if its even possible anymore). the check was intended to compare two non-null roots iirc, so we shouldn't be running that logic at all if either side is nullish |
Sorry for the delay and thank you a lot for the response. This actually sounds reasonable and I'm happy to create a PR for this particular scenario. Locally it works fine with a new test added for an element within a closed shadow root. |
… a closed ShadowDOM. As discussed on issue SeleniumHQ#13132 the "Get Text" atom currently fails for elements that are located within a closed ShadowDOM. In those cases a check for ".shadowRoot" will not succeed because it's "null". This patch fixes the check by making sure that it is only run when a valid ShadowRoot is actually available. # Please enter the commit message for your changes. Lines starting
… a closed ShadowDOM (#13211) "Get Text" atom has to return the visible text from an element within a closed ShadowDOM. As discussed on issue #13132 the "Get Text" atom currently fails for elements that are located within a closed ShadowDOM. In those cases a check for ".shadowRoot" will not succeed because it's "null". This patch fixes the check by making sure that it is only run when a valid ShadowRoot is actually available. # Please enter the commit message for your changes. Lines starting
… a closed ShadowDOM (SeleniumHQ#13211) "Get Text" atom has to return the visible text from an element within a closed ShadowDOM. As discussed on issue SeleniumHQ#13132 the "Get Text" atom currently fails for elements that are located within a closed ShadowDOM. In those cases a check for ".shadowRoot" will not succeed because it's "null". This patch fixes the check by making sure that it is only run when a valid ShadowRoot is actually available. # Please enter the commit message for your changes. Lines starting
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
What happened?
Originally filed as a geckodriver issue: mozilla/geckodriver#2097
Since Firefox 108 the
Get Text
atom only returns an empty string for elements inside of a ShadowDOM. Over on https://bugzilla.mozilla.org/show_bug.cgi?id=1824664 I've made some investigations and manually reverted the changes ofjavascript/atoms/dom.js
until the problem is gone. The causing change is the following:9e5016d#diff-53bbf9a76b3e18a714284bd37ffdbcb670cbf537319cdaee94aacca31bcc497d
CC @43081j, @shs96c
How can we reproduce the issue?
Relevant log output
Operating System
All
Selenium version
Latest
What are the browser(s) and version(s) where you see this issue?
Firefox since version 108
What are the browser driver(s) and version(s) where you see this issue?
geckodriver 0.33.0
Are you using Selenium Grid?
No
The text was updated successfully, but these errors were encountered: