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:
@FindBy(how = How.ID, using = “foo”),
@FindBy(className = “bar”)

So, above lines of code can be written as below:

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

6 thoughts on “FindAll Annotation In Page Factory In Selenium WebDriver

  1. hi Amod,

    above code if elements are find by class name ,will ignore the id related elements or how it works can u explain

    @FindBy(className = “ABC”),
    @FindBy(id = “DEF”),
    @FindBy(linkText = “Sometext”)

    in blog you said any of @findBy criteria if elements are found with class name then page factory will ifnore the findBy(id) and other one?

  2. HI Amod

    Can I know what are How , how and we user using the syntax. Can i know what exactly are they. I was asked in one of the interview regarding that


Leave a Reply

Your email address will not be published. Required fields are marked *