Skip to content

Instantly share code, notes, and snippets.

@djangofan
Last active August 29, 2015 14:13
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 djangofan/27374b054884730596ff to your computer and use it in GitHub Desktop.
Save djangofan/27374b054884730596ff to your computer and use it in GitHub Desktop.
Verbose elementExistsWithText for Selenium
public Boolean elementExistsWithText(By locator, String text)
{
ExpectedCondition<Boolean> textToBePresentInElement = ExpectedConditions.textToBePresentInElementLocated(locator, text);
WebDriverWait wait = webDriverManager.getCachedWebDriverWait(webDriverManager.DEFAULT_WAIT);
try {
wait.until(textToBePresentInElement);
return Boolean.TRUE;
} catch ( WebDriverException wde ) {
LOG.debug( "Element '" + locator.toString() + "' with text '" + text + "' was not present.", wde);
return Boolean.FALSE;
} catch ( TimeoutException te ) {
LOG.debug( "Element '" + locator.toString() + "' with text '" + text + "' was not found within timeout.", te);
return Boolean.FALSE;
}
}
public Boolean verboseElementExistsWithText( By locator, String text) {
long startTime = System.nanoTime();
Boolean result = elementExistsWithText(locator, text);
long endTime = System.nanoTime();
long duration = (endTime - startTime);
LOG.debug( "Element '" + locator.toString() + "' with text '" + text + "' gave up search after + ((double)duration / 1000000000.0) + " seconds." );
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment