Page Object Model in Selenium

Page Object Model in Selenium

1) What is Page Object Model?

> Page Object model is an object/Element design pattern to create Object Repository for web elements/objects (Ex: Links, Buttons, Edit boxes etc...).

> Under this model, container classes for web elements are created that behave as object repositories.

> We can create POM in 2 ways, 1) POM without Page Factory, 2) POM with Page Factory In this session I am going to explain POM without Page Factory.

> No Object Repository facility in Selenium WebDriver, It is a programming 
  Interface, If it is UFT/QTP We have Object Repository facility (local and shared
  Object repositories)

> Under this model, for each web page in the application, there should be 
   corresponding page class.

> This Page class will find the Web Elements of that web page and also contains the methods which perform operations on those Web Elements.

> If no Object Repository/Page Object Model then it is difficult to maintaing 
  objects/Elements in Test cases...
2) Advantages of Page Object Model

> Centralized maintenance of elements/objects

> Reusability, reduces duplication of code

> It is Efficient and Scalable

> It makes the framework user friendly.
3) Disadvantages of Page Object Model

> Initial effort investment in development of Automation Framework is high.

> It is not a generic model, automation framework developed using POM approach is  specific to the application. 
4) Implement Page Object Model

> In this approach all pages web elements of the application and the user actions on these Web Elements are maintained as methods inside a class file. By importing the page classes then we can create Test cases easily.
Create Page Class...

public class LoginPage {
WebDriver driver;


public LoginPage(WebDriver driver){
public void typeUsername(String uname){

public void typePassword(String pass){

public void clickLoginButton(){

public void clearUsername(){

public String captureUsername(){
return driver.findElement(Username).getAttribute("value");

Test Cases Class

public class TestCases {

public static void main(String[] args) throws InterruptedException {

System.setProperty("", "E:/chromedriver.exe");
WebDriver driver=new ChromeDriver();
LoginPage login=new LoginPage(driver);


String URL=driver.getCurrentUrl();

if (URL.contains("")){
System.out.println("Admin Login Sucessful-Passed");
System.out.println("Admin Login Sucessful-Failed");


Sir, i want to select a drop down value using Page Object Model framework. Could you please let me know how to do it.

Here dynamic Xpath will be used, the value which you want to select will be passed in xpath and using Select class, you can specify the webelement.

Post a Comment