1

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 .

Nick Kinlen
  • 1,356
  • 4
  • 30
  • 58
ShSharma
  • 9
  • 3
  • In the future indent code by highlighting the code and pressing `control` and `k` or by pressing the code button on the form. – Nick Kinlen May 12 '20 at 02:40

1 Answers1

0

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()")
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I tried with below code but always getting error javascript evaluation failed: * def ele = script('paper-drawer-panel', "_.shadowRoot.querySelector('paper-listbox#menu')") – ShSharma May 12 '20 at 21:16
  • i tried with js path also of the element but still getting the same error: document.querySelector("body >app").shadowRoot.querySelector("#drawerPanel") – ShSharma May 12 '20 at 21:37
  • @ShSharma please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - also if you see the questions by others, they have provided links to sample pages clearly explaining the problem. if you can't - then don't expect any help – Peter Thomas May 13 '20 at 02:53
  • I tried with all the ways given by others and follow all the links...Still i am not able to click on child element using above code and other examples. – ShSharma May 13 '20 at 04:41
  • @ShSharma I have nothing more to add to my above comment. you can wait to see if any others here can help, I don't think it is likely though. all the best – Peter Thomas May 13 '20 at 04:43
  • 1
    By this code i am able to access shadow root element using karate * script('document.querySelector("body > nuxeo-app").shadowRoot.querySelector("#menu > nuxeo-menu-icon:nth-child(1)").shadowRoot.querySelector("#button").shadowRoot.querySelector("#icon").click()') Thanks for helping me.Karate is really awesome framework. – ShSharma May 18 '20 at 22:09