Skip to content

Instantly share code, notes, and snippets.

@selenium-in-action
Last active May 28, 2017 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selenium-in-action/92057da655fc6812bfe0fe12f0494e7c to your computer and use it in GitHub Desktop.
Save selenium-in-action/92057da655fc6812bfe0fe12f0494e7c to your computer and use it in GitHub Desktop.
Check if element is displayed (and catching NoSuchElementException)
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