Read data from Property File in Selenium Script using JAVA

In Selenium based JAVA project, .Properties files are used mainly to store configuration data like application URLs, database credentials etc. and web element locators.
.Properties file stores the data in a form of key & value pair as shown below:


Sample Project Structure:


Let’s try to understand it by using below scenario:

1. Open URL :
2. Read the search text box locator from property file and type ‘selenium’.
3. Close browser.


import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;

public class SampleTests {

	public void test_propRead() throws Exception {
		System.setProperty("", System.getProperty("user.dir") + "/driver/chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		Properties propertyReader = getPropertyFile("");
		String textBoxLocator = propertyReader.getProperty("searchTextbox");

	public Properties getPropertyFile(String fileName) throws Exception {
		File file = new File(System.getProperty("user.dir") + "/src/com/selenium/config/" + fileName);
		FileInputStream fileInputObj = new FileInputStream(file);
		Properties propObj = new Properties();
		return propObj;


If you see in above program, getPropertyFile() method is called to initialize the file and .properties file name is being passed as a parameter and this method will return the Properties class object.

Once initialization is done, then getProperty() method of Properties class is being called to get the value of any key stored in that Property file. It is that simple.

If you really like the information provided above, please don’t forget to hit a like on Facebook Page, you can also leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *