Open
Description
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?