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 23, 2019 in Selenium by Neha
• 6,300 points
3,827 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 23, 2019 by Frankie
• 9,830 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 4, 2020 in Selenium by Sri
• 3,190 points
1,758 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,140 points
7,664 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,500 points
13,674 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,190 points
9,143 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,910 points
7,221 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 3, 2020 in Selenium by Sri
• 3,190 points
7,874 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,830 points
15,826 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,830 points
4,290 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP