How to Read and Write excel files in Selenium using Apache POI

Hello, Welcome to Selenium tutorial, in this post, we will see how to Read and Write excel files in Selenium

Selenium support only Web browser automation so for Read and Write excel files in Selenium we have to take help of third party API like JExcel and Apache POI

Apache POI is an API, which is freeware and written in Java and gives so much flexibility to read/write files it has so many predefined methods, classes, and interfaces.

Once you move to next step like designing framework then you must be familiar with excel file. We have to use this concept while designing Data Driven Framework as well.

Another point this is one of the most important questions in interviews as well and you should be having complete knowledge of it.

 

Read and Write excel files in Selenium

Step 1- Download apache poi jar file as below

Go to Official website of Apache POI and Click on the download section

http://poi.apache.org/download.html

Read and Write excel files in Selenium

Read/Write Excel file in Selenium

 

Now Click on the below mention link

Read and Write excel files in Selenium

Read/Write Excel file in Selenium

 

All jar files will come in zip files, Extract it and you will get final jar folder looks like this

Read/Write excel files in Selenium

Read/Write Excel file in Selenium

Add all jar files or below mention, jar files into Project.

 

Read/Write excel files in Selenium

Read/Write Excel file in Selenium

Step 2- How to add Jar files

Select project then Right click on project > Build path > Configure build path > Click on lib section > Add external jar
Precondition- Create a xlsx file and enter some data to read and save file at particular location.

 

Read Excel file using Apache POI

In below example, I am reading simple .xlsx file

 

 

Write Excel file Selenium Webdriver

Now if you are familiar with reading excel then it is just a cup of tea now

In below example, I am  writing .xlsx file

 

Some companies also use CSV files to store the data and some also use Databases to store the data so based on your requirement you can select any data source.

I hope you have enjoyed the article if yes then share with your friends and colleagues as well.

Please comment in below section if you are facing any issue. Thanks For visiting my blog keep in touch

104 Comments

  1. Nikhil
  2. Dinesh Guptha Sivaguru
      • Dinesh Guptha Sivaguru
  3. Narayan Boolchandani
  4. Waheed Ahmed
  5. Dinesh Guptha Sivaguru
  6. Daisy G
  7. khushali
  8. Lavanya
  9. Anjana

Leave a Reply