FindAll Annotation In Page Factory In Selenium WebDriver
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
A software Tester who is paid to judge products developed by others. Writing technical posts and creating YouTube videos are my hobbies.
6 thoughts on “FindAll Annotation In Page Factory In Selenium WebDriver”
Do we need to initialize the following using PageFactory.initElements
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?
What is the such and where it can be implemented in real time scenario?
Think of it.
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
Hello, can you reframe your question again?