What is difference between POM and Page factory in selenium webdriver Java?

Solved 1 Answers 522 Views

What is the difference between Page object model and Page factory model in selenium webdriver Java?

I want to know each one with detailed examples .Is it possible to use with Selenium C# also?

Kindly reply me.

1 Answer

Best answer

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


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.

Feel free to comment back if you need more details.

answered Feb 10 by stbadmin (4,970 points)
selected Mar 3 by stbadmin