Make Selenium Easy

Creating Object Repository In Selenium WebDriver Using Properties File As An External Source

Hello Folks,

We have seen Page Object Model in previous posts and you must be noticing that we are writing locators within code. It has its own disadvantages as below:

  1. For any modification in locator, you must need to touch the code.
  2. Difficult for manual tester or beginner in automation testing to find out correct place to change locator if needed.

So, we can also read locators from externals sources like:

a. Database
b. Properties file
c. XML file
d. Excel sheet

Database and Properties file are mostly used as external source of locator to create object repository. We will see how to create object repository using properties file.

What is properties file in Java?

A file with extension .properties in java, is called a property file which stores the data in form of key value pair (Like Map). We can store our locators in a properties file and we can read it from properties file and we can use to create object repository.

How to read data from properties file?

Step 1: Create a file with extension .properties as “”.

Step 2: Load the properties file using load() method of Properties class.

Step 3: Use getProperty(String key) to read value using Key.

We will see step by step now.

Step 1: Let’s start by creating a properties file.

We will store the value as:

WebElementName = LocatorType:LocatorValue

It will help in locating web element using desired locator.

Create a class to load properties file:

We will create a class which will have methods for loading properties file and locating web element .

Script class:

That’s it guys. Hope you would have clear concepts now.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

6 thoughts on “Creating Object Repository In Selenium WebDriver Using Properties File As An External Source

  1. Hi, Why when i try using this solution, i use like:

    WebElement txtEmail = driver.findElement(prop.getLocator(“EmailAddress”));

    i got like:

    Unhandled exception type Exception

    even i declare : PropertiesUtils prop = new PropertiesUtils(“./”);

    What i am doing wrong?

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.