How to Read Test Data from CSV File in Selenium Webdriver

In this post, we are going to see how to “Read CSV Files In Selenium WebDriver”. well, It’s a common requirement for any organization to use some sort of data driven approach as part of Automation Testing Framework. Most often, Excel files are used for this purpose because of their extensibility but there could be a situation where Test Data is required to maintain in CSV formatted files instead of Excel sheets. 
So in this example, let’s read test data from a CSV file to perform data driven software testing in selenium WebDriver.

In this tutorial, we are going to cover below points:


Let’s begin:

1. What is a CSV File?

CSV stands for Comma Separated File. It is a tabular representation of data in a plain text format. Each data value is separated by a comma sign.

If you look at the below image, Each line depicts a row and each comma separate data value is a column. 

CSV File

2. Pre-requisites : How to Setup OpenCSV library in a Project & Prepare Test Data CSV

In order to start the implementation of Data driven testing using CSV as your data source, we need to set up the environment first. For this reason, this tutorial will explain and help to set up the prerequisite and required dependencies in Eclipse.

Maven based Project:

If you are using Maven as the build tool for you project, use below mentioned dependency and add it into the POM file:


If you are using standalone project then download the OpenCSV jar from this location and add it into your project’s class-path.

Now, as a second pre-requisite, Create a CSV format Test data file that you are going to use in our test. Download TestDataCSV  as we are using this in below example.


3. Read CSV Files in Selenium

Now, as you’ve added the dependency into the project and Test data CSV file is ready too, now, use the below code to read the data present in that CSV File.


Check below video to see the execution in progress:


That’s it. So easy to implement.

Happy Learning!!!

4. Resources

Data Driven Approach – Elemental Selenium

Read Data From CSV In Selenium Webdriver...!!! Click To Tweet

Checkout other useful tutorials, take a look:

Rest Assured Tutorial

Apache HttpClient Tutorial


Related Posts:

[wcp-carousel id=”5342″]

Leave a Reply

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

Facebook Twitter Instagram YouTube