Object Repository in Selenium Using Page Factory With Inner Class – Handling a Page Which Has Many Webelements

Hello Folks,

You must have seen a web page which contains many divisions or multiple web elements and similar web elements in multiple divisions. Creating a web element repository for such pages is difficult in some cases which are given below:

  • If you have many web elements in a page, Selecting desired web elements while using is difficult. As soon as you type connector (dot (.) ) operator , it will list all the web elements present in that page and you need to search from them. However this can be made simpler using Naming Convention approach.
  • If you have common web elements in multiple division of same web page, you need to provide proper differentiation in names so that anyone can easily identify desired one.

 

We can resolve above issues using inner class concept of Java. We can divide each section as a static inner class. It will also initialise only particular section web elements instead of all web elements of page.

Sample code:

In Test script class, you just need to access required inner class as below:

Hope this will be helpful for you to create an object repository for a page which has multiple divisions and web elements.

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

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning