问题
Using selenium we can access it in this way:
def expand_shadow_element(element):
shadow_root = driver.execute_script('return arguments[0].shadowRoot', element)
return shadow_root
outer = expand_shadow_element(driver.find_element_by_css_selector("#test_button"))
inner = outer.find_element_by_id("inner_button")
inner.click()
So in similar way, I tried to find using karate in .js file, write the below code
expand_shadow_element(element):
shadow_root = driver.execute_script('return arguments[0].shadowRoot', element)
return shadow_root**
//And call the .js file in feature file by below code:
def ele = expand_shadow_element(locate('#drawerPanel'))
But it's not working for me .
回答1:
Just use script()
to easily fire any arbitrary JS in the page.
Here is an example: https://stackoverflow.com/a/60618233/143475
* script('hangout-module', "_.shadowRoot.querySelector('button').click()")
来源:https://stackoverflow.com/questions/61742447/how-we-can-access-shadow-dom-tree-elements-using-karate