How do i use javascript executor in Karate UI

Can you switch to XPath and see if that helps:

* def temp = script('//downloads-manager', '_.innerHTML')

Else please submit a sample in this format so we can debug: https://github.com/intuit/karate/tree/develop/examples/ui-test

EDIT: after you posted the link to that hangouts example in the comments, I figured out the JS that would work:

* driver 'http://html5-demos.appspot.com/hangouts'
* waitFor('#hangouts')
* def heading = script('hangout-module', "_.shadowRoot.querySelector('h1').textContent")
* match heading == 'Paul Irish'

It took some trial and error and fiddling with the DevTools console to figure this out. So the good news is that it is possible, you can use any JS you need, and you do need to know which HTML element to call .shadowRoot on.

EDIT: for other examples of JS in Karate: https://stackoverflow.com/a/60800181/143475

Leave a Comment