Delivered by FeedBurner

Selenium WebDriver DDF : Creating Object Repository To Store Element Objects

In Selenium WebDriver software test data driven framework creation STEP 26, We have Implemented simple calc software test. Now In this step, We will create object repository using .properties file to store software web page element's locators like xpath Locator, cssSelector Locator, className Locator, id Locator, linkText Locator, name Locator,
partialLinkText Locator and tagName Locator. We can call It as object repository because we are storing objects In that .properties file.
Prerequisite : All the previous 26 Steps of selenium webdriver DDF creation should be Implemented. You can get links of all previous steps on THIS PAGE.

Why need to create object repository?
Supposing you have 100 software test cases and there Is one button or text box or any other element which Is used In 50 software test cases. Now for some reason, XPath or id or cssSelector locator of that element Is changed on software web page which you have used In 50 test cases. In this situation what you will do? You will go to change element's locator In all 50 test cases? It Is just waste of time and It will create many complexity and errors In code.

Best way to handle this situation Is creating object repository. As described In first paragraph, Object repository will store the element objects. So you need to store all the element's objects In single .properties file and then you can use It's key In your test cases wherever required. Now If above scenario happens then you have to modify your element's locator In .properties file only.

How to create object repository
For creating object repository, You have to Insert new file under package to store element's locators.

How to call object from file
First of all, We have to Initialize file before test case execution. So we will Initialize It Inside init() function of file. And then we can call any object Inside our test case using It's key.

Example :
Supposing, there Is one button +(plus) In calc application whose XPath Is "//input[@id='plus']". So you can store It In file as bellow.


Here btn_Plus Is the key of that XPath. So now If you wants to click on that button In your test case then you can use bellow given syntax In your test case.


This Is Just example, Same way you can call all other required objects In your test cases from file.

Download required files
You need modified, and files. Download bellow given zip folder to get all these files.
Add/Replace files as bellow
  • Add Under Package
  • Paste File on com.stta.TestSuiteBase Package.
  • Paste File on com.stta.SuiteOne Package.
Now your project structure will looks like bellow.

I have added comments In and files to understand code better.

Run test suites and observe results
Run your test from Shortcut to Run Test.bat file. Now will read element's objects from file.

What we have achieved In this step
We have created object repository for our selenium webdriver data driven framework. So from now onward, we will store all our objects In file. Benefits of creating object repository In webdriver DDF are as bellow.
  • Easy to maintain the software web page's objects elements.
  • Decrease the size of code.


  1. Hellp,
    I'm working on Keyword Driven Framework on Eclipse using Java. I'm having a problem with object repository has long xpath like this.


    is this correct?

    1. If you are using .properties file, then it is correct way of declaring the locator.
      If you are using .java fie to store the locators then you have to mention as follows
      String = "";
      ex: public final String btn_LogOut = "/html/body/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr/td[1]/a";

      I hope your issue solved