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

Add support for shadow elements #7808

Conversation

diego-fernandez-santos
Copy link
Contributor

@diego-fernandez-santos diego-fernandez-santos commented Nov 23, 2019

Atoms checks if an element is still attached to the DOM before every interaction. This check is done here. The problem is that it doesn't take into account shadow elements. These elements doesn't have a parentNode but they can still be attached to the DOM, for example shadowRoot elements.

If you try to interact with WebComponents in IPhone an "Element is no longer attached to the DOM" error would be raised.

I do this pull request in this branch because this is the current version that appium-remote-debugger currently using.

You can replicate this problem directly in the browser following the next steps:

var doc = { documentElement : document }

  var element = document
    .querySelector('shop-app').shadowRoot
    .querySelector('shop-home').shadowRoot
    .querySelector('shop-button a');

  function getElementIfAttached(el) {
    var node = el;
    while (node) {
      if (node == doc.documentElement) {
        return el;
      }    
      node = node.parentNode;
    }
  }

  getElementIfAttached(element)

You can see that getElementIfAttached doesn't return the element although the shop-button is still attached to the DOM.

@CLAassistant
Copy link

CLAassistant commented Nov 23, 2019

CLA assistant check
All committers have signed the CLA.

@@ -524,6 +524,9 @@ bot.inject.cache.getElement = function(key, opt_doc) {
if (node == doc.documentElement) {
return el;
}
if (node.host && node.nodeType === 11) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of host I think that you want to node.ownerDocument to check if fragment is still attached.

Does this work on ShadowDOM as they are not document fragments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the change.

I use that other way to try to keep the same code style. I think that it was valid (according to the last W3C). However I think that your recommendation is faster.

@imurchie
Copy link
Contributor

This latest iteration doesn't work on MobileSafari, on any version of iOS I try. The first solution did work. At the point of failure, node.ownerDocument.parentNode does not exist but node.host.parentNode does.

imurchie referenced this pull request in appium/appium-remote-debugger Dec 26, 2019
@AutomatedTester AutomatedTester merged commit 2eeb6a9 into SeleniumHQ:master Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants