public static ExpectedCondition < Boolean > attributeToBe ( final By locator , final String attribute , final String value ) { return new ExpectedCondition < Boolean > ( ) { private String currentValue = null ; @ Override public Boolean apply ( WebDriver driver ) { WebElement element = driver . findElement ( locator ) ; currentValue = element . getAttribute ( attribute ) ; if ( currentValue == null || currentValue . isEmpty ( ) ) { currentValue = element . getCssValue ( attribute ) ; } return value . equals ( currentValue ) ; } @ Override public String toString ( ) { return String . format ( "element found by %s to have value \"%s\". Current value: \"%s\"" , locator , value , currentValue ) ; } } ; }
An expectation for checking WebElement with given locator has attribute with a specific value