How to use property file as a object repository in Selenium WebDriver Automation

0 votes

How to use property files as an object repository in Selenium WebDriver Automation?

Jan 22, 2019 in Selenium by Neha
• 6,300 points
2,213 views

1 answer to this question.

0 votes

Create any file & save it with .properties extension For example - Add new file in eclipse By right click on project > New > Fille and add below properties.

Username = xyz
Password = 123

Write Below code to access this file

String filepath = "./config.properties" ; // Path of .properties file
File f = new File(filepath); 
FileInputStream fs = new FileInputStream(f);

Properties pro = new Properties();
Pro.Load(fs);
pro.getProperty("Username"); // return value "xyz"  return type string 
pro.getProperty("Password"); // retun  value "123" return type string

Also, use-

driver.findelement(By.id("user")).sendKeys(pro.getProperty("Username"));
driver.findelement(By.id("pass")).sendKeys(pro.getProperty("Password"));
answered Jan 22, 2019 by Frankie
• 9,810 points

Related Questions In Selenium

0 votes
1 answer
0 votes
2 answers

How to use link as a locator to find element in selenium?

driver.findElement(By.linkText("link")).click(); READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,070 points
464 views
0 votes
1 answer
0 votes
1 answer

How to pass parameter through testng.xml file to a test case in Selenium Webdriver?

Hello Revathi, to pass parameter through testng.xml ...READ MORE

answered Jun 12, 2019 in Selenium by Abha
• 28,040 points
4,422 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
5,561 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,070 points
6,169 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
3,825 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,070 points
4,709 views
0 votes
1 answer

How to send ALT/SHIFT/CONTROL key in Selenium WebDriver?

When we generally use ALT/SHIFT/CONTROL keys, we ...READ MORE

answered Feb 8, 2019 in Selenium by Frankie
• 9,810 points
12,078 views
0 votes
1 answer

How to skip a method or a code block in TestNG?

If you want to skip a particular test ...READ MORE

answered Feb 8, 2019 in Selenium by Frankie
• 9,810 points
1,219 views