public static ExpectedCondition < Boolean > elementSelectionStateToBe ( final WebElement element , final boolean selected ) { return new ExpectedCondition < Boolean > ( ) { @ Override public Boolean apply ( WebDriver driver ) { return element . isSelected ( ) == selected ; } @ Override public String toString ( ) { return String . format ( "element (%s) to %sbe selected" , element , ( selected ? "" : "not " ) ) ; } } ; }
An expectation for checking if the given element is selected .