Plain Page Object Model In Selenium Webdriver (Without PageFactory)

Hello Folks,

In last post, we have seen Introduction of Page Object Model in details.

In this post we will see how to implement page object model in selenium webdriver.

The main idea of POM is to separate web elements and test scripts to achieve one to many relationship. You define web element at single place and you can use that in many scripts. It makes maintenance of web elements easy if you want to modify or add new.

To achieve this, we can store web elements in a property file, an excel file, in a java class or in table of database. In this post, we will store web elements in a java class file.

POM does not say anything specifically on categorization of web elements but it is good practice to group web elements as per web page name. For example: Web elements present on login page should be stored in class and web elements on registration page should be stored in Advantage of this approach will be easy accessing of web elements.  You just need to navigate to LoginPage.class to access login page web elements.

We will implement POM for below scenario:

  1. Access this URL.
  2. Click on Sign In button which is in Home page.
  3. Type Email Address in Email Address text box which is in Login page.
  4. Type password in Password text box which is in Login page.
  5. Click on Sign In button which is in Login page.

In above scenario, we will access two web pages “Login” and “Home” pages. So, we will create two java class: and

There is another good practice in POM is to keep actions/methods on web elements on same page. For example: You need to click on SignIn button. So, you should create a method clickOnSignButton method and keep in class.

Note: SignIn button is in LoginPage and HomePage both. POM helps you in distinguish similar web elements as well.



Disadvantages of Plain POM:
1. Its not optimized. More memory utilization.
2. No Lazy initialization.

Selenium has inbuilt page object model called PageFactory which is more advanced and optimized which we will see in next posts.

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

3 thoughts on “Plain Page Object Model In Selenium Webdriver (Without PageFactory)

    1. You can use method as well. Here constructor will help in initialising instance of class and keep track of same reference of driver.

Leave a Reply

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