How we can access shadow Dom tree elements using karate?

ⅰ亾dé卋堺 提交于 2021-02-10 14:13:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!