Selenium Diff between POM page object model and page factory

0 votes

Seems like Page object model & page factory are doing similar things. 

IpmObjectInitializer initialize = new IpmObjectInitializer(driver.getWebDriver());

By using page factory: Initialize elements in BatchCreationPageFactory class

batchCreationPageFactory = initialize.getBatchCreationPageFactoryObj();
Apr 18, 2018 in Selenium by kappa3010
• 2,090 points
6,493 views

2 answers to this question.

0 votes

Page Object Model in Selenium is a design pattern to create an Object Repository for web UI elements.
However, Page Factory in Selenium is a built-in class for maintaining object repository. For that, we can import the package: Page Factory.

public class LogInPage
{
    private WebElement usrnm;
    private WebElement pwd;

    public LogInPage() {
    }

    public void locateElements() {
        usrnm = driver.findElement(By.id("userName"));
        pwd = driver.findElement(By.id("password"));
    }

    public void doLogIn() {
        usrnm.sendKeys("qwe");
        pwd.sendKeys("123");
    }
}

With Page Factory, initElement() statement can be used for easily looking up elements in page class.
Page Factory allows storing of page elements in cache memory using @CacheLookup annotation
So, which ever methods we have defined in a diff class, those can be imported by using the page factory library.

public class LogInPage
{
    @FindBy(id="userName")
    private WebElement usrnm;

    @FindBy(id="password")
    private WebElement pwd;

    public LogInPage() {
        PageFactory.initElements(driver, this); // initialize the members like driver.findElement()
    }

    public void doLogIn() {
        usrnm.sendKeys("qwe");
        pwd.sendKeys("123");
    }
}
answered Apr 18, 2018 by king_kenny
• 3,710 points
0 votes
Hi,

In POM (Page Object Model) you create new class for every new page/URL and put all your element identification methods in it.

Eg.

If you navigate to my Github - OrangeHRM automation sample project, you will notice that I have two .java files there. Dashboard and Login. So whatever element I identify on Login page, I put in Login.java and whatever elements I identify on Dashboard, I put it in Dashboard.java. This is really helpful in terms of maintenance and usability. So, if I want to work with any element present on Dashboard, I just have to say Dashboard.element. If case of change of element, I just have to change it at one place.

Page Factory is annotation inside selenium which you give it to class. So, when you define any class as page factory, all your elements inside the class will get loaded while any of element in the class is called. This is really a bad practice if you have 100s elements inside a class and you just have to make use of only one.

So, I would suggest you to go with POM. I do not have C# example, but I have similar one in Java which I have already shared.
answered Mar 14, 2019 by Ellen Dares

Related Questions In Selenium

0 votes
1 answer
+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered Jan 13, 2020 in Selenium by Karan
• 19,610 points
8,397 views
0 votes
1 answer

What's the diff between Selenium RC and Selenium WebDriver?

RC works by injecting the JavaScript functions ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
1,348 views
0 votes
2 answers

What is Page Object Model in Selenium WebDriver?

POM is one of design pattern. maintenance  should ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
1,452 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,776 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,190 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,266 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,902 views
0 votes
1 answer

What is the difference between thoughtworks.selenium and openqa.selenium selenium?

thoughtworks.selenium is the original Selenium (aka Selenium 1, ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,710 points
3,010 views
0 votes
1 answer

Diff between WebDriver listeners and TestNG listeners?

This is not a very important concept ...READ MORE

answered Apr 14, 2018 in Selenium by king_kenny
• 3,710 points
6,522 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP