To check if element is visible we need to use element.isDisplayed();
But if we need to check for presence of element anywhere in Dom we can use following method
public boolean isElementPresentCheckUsingJavaScriptExecutor(WebElement element) {
JavascriptExecutor jse=(JavascriptExecutor) driver;
try {
Object obj = jse.execute("return typeof(arguments[0]) != 'undefined' && arguments[0] != null;",
element);
if (obj.toString().contains("true")) {
System.out.println("isElementPresentCheckUsingJavaScriptExecutor: SUCCESS");
return true;
} else {
System.out.println("isElementPresentCheckUsingJavaScriptExecutor: FAIL");
}
} catch (NoSuchElementException e) {
System.out.println("isElementPresentCheckUsingJavaScriptExecutor: FAIL");
}
return false;
}