The element is visible and clickable, but clicking the element is not working. Trying to catch exception and show the error message.
try {
element.click();
} catch (WebDriverException e) {
// how to print out error? also tried: System.out.println(...)
e.printStackTrace();
// how to catch exception/error from javascript?
((JavascriptExecutor)driver).executeScript(
"arguments[0].click()", element);
}
Questions:
how to print out exception? Could not find the stacktrace in console(windows) or test report html.
how to catch exception/error from executing javascript?
element.click()is a big antipattern. A reasonable approach is to develop some click handler function, to be called from both"click"handler and elsewhere. Now, catching exceptions here and there is also bad practice. But if you use this function, you cantryandcatchsuccessfully. But why? Okay, you decide.