Selenium Lesson 18 – Page Object Model Based Automation Framework


Page object model (POM) based automation framework is widely used automation framework for web based applications. it is effectively being used with selenium. Page object model (POM) can be used in any kind of framework such as data driven, modular, keyword driven etc. Page object model gives more focus on how the code is being structured to get the best benefit out of it. it has its own positive and negative sides.

What is Page Object Model?

In Page Object Model code is arranged or write considering the functionality present on the webpage. All Objects and Actions which can be performed on that object on the webpage get stored in one class file.

page object model

Lets take an example:

Suppose for login page we want to apply Page object model.




Step 1 : Create New class file:

First step will be creation of new class file. its always preferred to give the class name same as web page name, so in this case class name will be

Step 2: Identify the Objects/Controls:

First step will be identifying the controls/objects on the web page. in this case followings are the objects

  1. UserName textbox
  2. Password textbox
  3. Sign in Button
  4. Not a Member Link
  5. Sign up Now Link

each web element should be uniquely gets identified and should be defined at class level.

we will use FindBy annotation and will define web element. so that we can able to perform actions on them.

for above controls my code will look like this

(Note all below code is pseudo code just to explain POM concept)

@FindBy(id = "username")
private WebElement txtuserName;
@FindBy(id = "password")
private WebElement txtpassword;
@FindBy(id = "button")
private WebElement btnsignIn;
@FindBy(textlink = "forgotpassword")
private WebElement linkforgotpassword;
@FindBy(textlink = "signin")
private WebElement linksignin;


Step 3 : Write the possible actions on the objects ( web elements)

in this  case following actions can be performed on web elements

  1. For Textbox :  set text, clear text
  2. For Button : Click, get text on button, get visibility status ( enable/disable)
  3. For Link : Click, get Link text


now we have write the method will perform this actions

For TextBox :

Public static void txtSetUserName(string userName)
 catch (NoSuchElementException e) {
 System.out.println("Exception message"+ e.getMessage());"Element is not found");
Public static void txtClearUserName()
 catch (NoSuchElementException e) {
 System.out.println("Exception message"+ e.getMessage());"Element is not found");

in similar we need to write code for identified controls.

Step 4: Create Business Reusable

Now we are ready to create business logic and create reusable components. on Business reusable class file, create following method.


public class TestCase{
PageObject Loginpage;
Public static void Login(String userName, String password)
Loginpage.txtsetusername (userName);
Loginpage.txtsetpassword (password);


we hope this article give you information about how the POM is and how to implement it in your project. if you have any queries, do let us know.


You might also like More from author