public static ExpectedCondition < List < WebElement > > numberOfElementsToBeMoreThan ( final By locator , final Integer number ) { return new ExpectedCondition < List < WebElement > > ( ) { private Integer currentNumber = 0 ; @ Override public List < WebElement > apply ( WebDriver webDriver ) { List < WebElement > elements = webDriver . findElements ( locator ) ; currentNumber = elements . size ( ) ; return currentNumber > number ? elements : null ; } @ Override public String toString ( ) { return String . format ( "number of elements found by %s to be more than \"%s\". Current number: \"%s\"" , locator , number , currentNumber ) ; } } ; }
An expectation for checking number of WebElements with given locator being more than defined number