How to fetch data as input from excel and use it as a input(username and password) to login in application.


How to fetch data as input from excel and use it as a input(username and password) to login in application.?

Any body have this code ready plz share with me.


Train Asked on July 13, 2015 in Selenium WebDriver.
Add Comment
  • 2 Answer(s)
    Best answer

    /* Code to Fetch Login and password from Excel file and supply it to goibibo login page */

    package apache.poi.datadriven.anonymous;

    import java.util.concurrent.TimeUnit;

    import junit.framework.Assert;

    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import org.junit.After;
    import org.junit.AfterClass;
    import org.junit.Before;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class LoginClass {

    private static XSSFWorkbook XLWBook;
    private static XSSFSheet XLSheet;
    private static XSSFCell XLCell;
    private static XSSFRow XLRow;
    private static final String XLFile = “D://Logins.xlsx”;                       // Path to Excel file where the Login and Password needs to be fetched

    private static WebDriver wd;
    private static String BaseURL;
    private static int rowStart = 0, colStart =0;
    private String login, pswd;

    public static void initialize(){
    wd = new FirefoxDriver();
    BaseURL = “[DF-Brand-EM]-GOO-[Only%20Goibibo]–[S]-[goibibo]&ef_id=UzqQHgAAAP8Lqq6F:20150713074225:s”;

    public void LoadBrowser(){
    wd.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    public void datadriven() throws Exception{
    //Enter Username from Excel
    setExcelFile(XLFile, “Sheet1”);
    for(rowStart=0 ;rowStart<XLSheet.getPhysicalNumberOfRows();rowStart++){
    login = getCellData(rowStart, colStart);
    pswd = getCellData(rowStart,colStart+1);
    System.out.println(“Trying with: ” + login +”/”+ pswd);

    public void closeBrowser(){


    public static void Closedown() throws InterruptedException{


    public static void setExcelFile(String XLFile, String Sheetname) throws Exception{

    FileInputStream ExcelFile = new FileInputStream(XLFile);
    XLWBook = new XSSFWorkbook(ExcelFile);
    XLSheet = XLWBook.getSheet(Sheetname);
    }catch(Exception e){


    //This method is to read the test data from the Excel cell, in this we are passing parameters as Row num and Col num
    public static String getCellData(int RowNum, int ColNum) throws Exception{


    XLCell = XLSheet.getRow(RowNum).getCell(ColNum);

    String Cellvalue = XLCell.getStringCellValue();

    return Cellvalue;

    }catch (Exception e){





    Train Answered on July 13, 2015.
    Add Comment

    Script is working .
    Thanks a  ton Suhabe_Shaikh,

    Train Answered on July 14, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.