Last active
May 28, 2017 20:37
-
-
Save selenium-in-action/92057da655fc6812bfe0fe12f0494e7c to your computer and use it in GitHub Desktop.
Check if element is displayed (and catching NoSuchElementException)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.By; | |
import org.openqa.selenium.NoSuchElementException; | |
import org.openqa.selenium.WebDriver; | |
public class DisplayUtil { | |
/** | |
* If exception occurs the element can't be visible | |
* | |
*/ | |
public static boolean isDisplayed(final WebDriver driver, final By by) { | |
try { | |
return driver.findElement(by).isDisplayed(); | |
} catch (final NoSuchElementException ex) { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment