Using Excel Sheet as BD – Selenium – (Read)

Hello guys !

Today I will post about how to use Excel Sheet as a database with Selenium.

– First create your BD as this example:

Sheet 1 – Consumers







Sheet 2 – Products: Now, you can create other sheets with information about the products or something that you want.

– Always save as .xls

– Create a class for open the Data base (Sheet) – remember download the lib jxl > Link with download of all versions

import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;

public class OpenDataBase {

Sheet sheet;
Workbook bddatabase;

    public Sheet Open() throws BiffException, IOException, Exception {

WorkbookSettings ws = new WorkbookSettings();

//Change for the folder of the .xls
bddatabase = Workbook.getWorkbook(new File("BD//BDFile.xls"), ws);  

//Change the name of your sheet
sheet = bddatabase.getSheet("tbclient");
return sheet;

public void Close(Workbook bddatabase) throws BiffException, IOException, Exception {




– Create a class to list all the informations inside of the sheet (table):

import org.openqa.selenium.WebDriver;
import jxl.Cell;
import org.openqa.selenium.By;

public void TestCase() throws BiffException, IOException, Exception {

// open Data base

// bring the cells from BD
for (int i = 1; i < opendatabase.sheet.getRows(); i++) {
Cell id_client = opendatabase.sheet.getCell(0, i);
Cell casenameBD = opendatabase.sheet.getCell(1, i);
Cell email = opendatabase.sheet.getCell(2, i);
Cell name = opendatabase.sheet.getCell(3, i);
Cell surname = opendatabase.sheet.getCell(4, i);
Cell date_born = opendatabase.sheet.getCell(5, i);
Cell gender = opendatabase.sheet.getCell(6, i);
Cell discount = opendatabase.sheet.getCell(7, i);
Cell pass = opendatabase.sheet.getCell(8, i);





If you have any questions, just write below !

Thank you 🙂

5 thoughts on “Using Excel Sheet as BD – Selenium – (Read)

    1. Hi Leandro !
      This code convert to Java own unicode format. If you have problems with some junk characters while reading Excel using this API or if you want support all european characters(accentuation, tilde, ç, etc…).

      Practical Example:
      The sheet with the contents could contain unicode, the åäö are multibyte characters, while the ASCII ones are normal single byte characters. It is most definitely not Latin1. If you print the “contents” string with printLn and redirect it to a hello.txt file, you will find that the letter “ö” is represented with two bytes, C3 B6 in hex. (195 and 179 in decimal.)

      Is it clear ? Bye 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.