Last active
August 29, 2015 14:13
-
-
Save djangofan/27374b054884730596ff to your computer and use it in GitHub Desktop.
Verbose elementExistsWithText for Selenium
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
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