1

I'm trying to get the equivalent of isDisplayed and isElementDisplayed functionalities from Selenium WebDriver:

//isDisplayed is used on an Element
console.log($('#abc').isDisplayed())

//isElementDisplayed is used on a browser
console.log(browser.isElementDisplayed('#abc"]'))

There are methods in Karate like "present" and "exist" not sure what's the difference of the two.

Upon searching, I found this JQuery below but not sure how to properly use it using the script method.

if($('#testElement').is(':visible')){
   //what you want to do when is visible
}

Both are not working:
* print locate('#abc').script("_.is(':visible')")
* print script("$('#abc').is(':visible')")
Don
  • 163
  • 12

1 Answers1

1

Yes, Karate does not have the direct equivalent of the "is visible in viewport" check, for reasons given here.

Which shouldn't be a "blocker" at all, as you already are on the right track, to use JS. I suggest you spend time reading this: https://github.com/intuit/karate/tree/develop/karate-core#karate-vs-the-browser

This should work if jQuery is available on the page as $:

* def visible = script(".my-css", "function(e){ return $(e).is(':visible') }")

Note that "visibility" is such a hard topic, even jQuery doesn't get it quite right: https://stackoverflow.com/a/8337382/143475

Maybe you should explore this API, but it may not be available in old browsers: https://developers.google.com/web/updates/2016/04/intersectionobserver

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248