Categories: Selenium Topics

Is It Possible To Use Page Factory Without FindBy In Selenium WebDriver?

Hello Folks,

We are learning about Page Object Model in selenium in previous posts. This is another part of that.

Selenium webdriver has inbuilt page object model which is called Page Factory where we write web elements(Page Objects) with it locators using annotation @FindBy. Does FindBy annotation mandatory for Page Factory?

Answer is NO.

We do not require to use FindBy annotation for a page object if it has id or name. Page Factory sets a lazy proxy for each of the WebElement and List<WebElement> fields that have been declared, assuming that the field name is also the HTML element’s “id” or “name”. This means that for the class:

public class Page
{
private WebElement submit;
}
there will be an element that can be located using the xpath expression “//*[@id=’submit’]” or “//*[@name=’submit’]”.

So below lines of code are same:

@FindBy(id=”SomeId”)
WebElement elementName;

AND

WebElement SomeId;

So to use other locators like xpath, css etc, we required FindBy annotation.
Example:

RegistrationPage.java:

Registration Script:

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

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

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

Recent Posts

TestNG Tutorials 50: DataProvider in TestNG – Understand Basics of DataProvider & How It Works

Hello Folks, In last post, we have seen Why do we need to use DataProvider in TestNG. Now we will…

2 days ago

TestNG Tutorials 49: Need of DataProvider Method in TestNG

Hello Folks, TestNG provides a beautiful functionality to parameterized our configuration and test methods so that we can execute the…

6 days ago

API Testing Tutorial Part 9 – Difference Between REST and RESTFul API

Hello Folks, As part of our API Testing series, we will see "Difference between REST and RESTFul API" in this…

1 week ago

API Testing Tutorial Part 8 – Introduction to REST & REST API

Hello Folks, As part of our API Testing series, we will see below topics in this post: What is REST? Six…

1 week ago

API Testing Tutorial Part 7 – HTTP Status Code Must To Be Remembered

Hello Folks, As part of our API Testing series, we will see some important HTTP status codes in this post.…

1 week ago

TestNG Tutorials 48: How to Pass Parameters of Different Datatypes in TestNG

Hello Folks, Most of us know that, we can pass parameter as a String to methods in TestNG class. Is…

2 weeks ago