public static ExpectedCondition < List < WebElement > > presenceOfNbElementsLocatedBy ( final By locator , final int nb ) { return new ExpectedCondition < List < WebElement > > ( ) { @ Override public List < WebElement > apply ( WebDriver driver ) { final List < WebElement > elements = driver . findElements ( locator ) ; return elements . size ( ) == nb ? elements : null ; } } ; }
An expectation for checking that nb elements that match the locator are present on the web page .