FindAll Annotation In Page Factory In Selenium WebDriver

Hello Folks,

In this post, we will learn about another annotation in Page Factory called FindAll.

Suppose, you need to locate below web elements and find out counts:

  1. All web elements whose class name is “ABC”.
  2. All web elements whose id is “DEF”.
  3. All web elements whose linkText is “Sometext”.

Generally you will write as below will take count of List for all and then get the sum.

But there is a better way to write above lines of codes in single line using @FindAll.

As per selenium doc: @FindAll is Used to mark a field on a Page Object to indicate that lookup should use a series of @FindBy tags. It will then search for all elements that match any of the FindBy criteria. Note that elements are not guaranteed to be in document order. It can be used on a types as well, but will not be processed by default. Eg: @FindAll ({ @FindBy(how = How.ID, using = “foo”), @FindBy(className = “bar”)

})