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:
- All web elements whose class name is “ABC”.
- All web elements whose id is “DEF”.
- 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.