Reading Data from Notepad Using Selenium WebDriver

Reading Data from Notepad Using Selenium WebDriver



Sometimes we came across requirements where we need to read the test data from notepad file and use this test data in automation test instead of a conventional way of storing either in excel or in the properties file.

In this article, we will learn how to read data from Notepad or .txt file.




For this purpose, we can make use of java built-in class File to create a new file, FileWriter, and BufferedWriter class to write In to file, FileReader and BufferedReader Class to read this text file.

In this example, I will read the data from the notepad file kept on my desktop which contains google home page URL and enters that URL in my chrome browser.


Below is the code snapshot




SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
February 3, 2020 at 8:03 PM

Hi Ankur, i am getting below error while executing same program in my local.
I have changed the path of .txt file as per my local drive.

Error:
Exception in thread "main" java.io.FileNotFoundException: C:\Users\satyendra.rajpoot\testdata.txt (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileReader.(Unknown Source)
at ExcelData.NotePadDataReadWrite.main(NotePadDataReadWrite.java:16)

Can you please help, same error i am also getting when i am using excel driven approach. Let me know if you any solution for this.

Reply
avatar
June 17, 2020 at 9:09 PM

Thanks its very use-full.

Reply
avatar