public static ExpectedCondition < Boolean > textToBe ( final By locator , final String value ) { return new ExpectedCondition < Boolean > ( ) { private String currentValue = null ; @ Override public Boolean apply ( WebDriver driver ) { try { currentValue = driver . findElement ( locator ) . getText ( ) ; return currentValue . equals ( value ) ; } catch ( Exception e ) { return false ; } } @ Override public String toString ( ) { return String . format ( "element found by %s to have text \"%s\". Current text: \"%s\"" , locator , value , currentValue ) ; } } ; }
An expectation for checking WebElement with given locator has specific text