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.
Author: Amod Mahajan
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning