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

Shadow-dom #50

Open
jrd opened this issue Apr 15, 2018 · 5 comments
Open

Shadow-dom #50

jrd opened this issue Apr 15, 2018 · 5 comments

Comments

@jrd
Copy link
Contributor

jrd commented Apr 15, 2018

Shadow-dom is very hard to test and to find elements.

find_element_XXX methods cannot pass through shadow-root and therefore great deal of effort should be done to reach some element if nested shadow elements are in the path.

It is also difficult to wait for some element to appear or desappear for the same reason.

driver.execute_script('return arguments[0].shadowRoot', element)

is enough to reach the shadow-dom of an element and from there, any other find_element_XXX method will work (until reaching another shadow dom of course)

Proposition to ease usage:

  • add a '> ##shadow-dom' in css selectors
  • add a '/#shadow-dom/' in xpath expression

that splits the css selector or xpath expression to get the shadow-dom of a element and continue descending in the selection.

Rough example:

def shadow(driver, element):
    driver.execute_script('return arguments[0].shadowRoot', element)


def find_element_by_css_selector(driver, selector):
    shadow_dom_selector = '> ##shadow-dom'
    selectors = selector.split(shadow_dom_selector)
    element = None
    for s in selectors:
        if element:
            element = shadow(element)
        else:
            element = driver
        element = element.find_element_by_css_selector(s)
    return element


tata = find_element_by_css_selector(driver, 'div.foo bar > ##shadow-dom baz.toto > #titi  > ##shadow-dom tata')

What do you think?

@jrd
Copy link
Contributor Author

jrd commented Apr 16, 2018

Interesting information: SeleniumHQ/selenium#4971 (comment)

@spyoungtech
Copy link
Owner

This would definitely be an interesting feature to explore. What I'll do in the coming week is investigate and understand interacting with the Shadow Dom via Selenium as best as I can.

As far as a possible interface for this in behave-webdriver, my main concern would be not affecting the behavior of finding elements not in a shadow dom.

As of right now, there's no provided step for locating/working with elements relative to other elements. Perhaps that may be a good angle to get at the shadow dom.

@spyoungtech
Copy link
Owner

Just chiming back in. Haven't forgot about this, things have just been a bit busy.

As a next step, I'm planning to put together a scenario or two for shadow dom into the demo app. If we implement something to make interacting with the Shadow Dom easier, I'm still contemplating what an elegant interface for this might look like.

@sunpala
Copy link

sunpala commented Jan 4, 2021

Hi @spyoungtech, I happened to find your comments while trying to figure out automating a Salesforce app that uses shadow dom, using selenium and Java. I realize now(from your comments), it's not going to be as easy I thought it would be. I was wondering if you have any updates following your investigation. Sorry, I am not trying to be cheeky, but it will be really useful to testers like me. Thanks

@spyoungtech
Copy link
Owner

Hi @sunpala unfortunately I've not yet found a great way to deal with this use case. Part of the difficulty is that support for shadow dom varies widely by browser.

Another unanswered question for me is how should a user specify this?

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

3 participants