Using a javascript script and Spin, how can I test for the existence of an element at an xpath? When I try and do this I get exceptions and can’t seem to be able to prevent the exception. In Java I can use a try/catch block and ignore the exception but this seems to fail in Javascript. Here is one example of what I have tried:
Java exceptions
Rhino wraps Java exceptions as a script object. If you want underlying Java exception, you’ve to use “javaException” property to access it. Nashorn does not wrap Java exceptions. Java exception objects as thrown “as is”. So, in catch blocks you can access Java exceptions “as is”.
Java exceptions
// rhino
try {
java.lang.System.loadLibrary(null)
} catch (e) {
// false!
print(e instanceof java.lang.NullPointerException)
// true
print(e.javaException instanceof java.lang.NullPointerException)
}
// in Nashorn, e instanceof java.lang.NullPointerException is true
// as there is no script wrapping of exceptions.