-2

I'm trying to read username and password from the excel file, below is my code but it shows following error :

log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager). log4j:WARN Please initialize the log4j system properly.

Code:

public static void main(String[] args) throws BiffException, IOException {      
    Sheet s;
    WebDriver driver = new FirefoxDriver();
    FileInputStream fi = new FileInputStream("E:\\myExcelWorkBook.xls");
    Workbook W = Workbook.getWorkbook(fi);

    s = W.getSheet(0);

    for(int row = 0;row <= s.getRows();row++){

    String Username = s.getCell(0,row).getContents();
    System.out.println("Username" +Username);
    driver.get("AppURL");
    driver.findElement(By.id("txtUserName")).sendKeys(Username);

    String password= s.getCell(1, row).getContents();
    System.out.println("Password "+password);

    driver.findElement(By.id("txtPassword")).sendKeys(password);

    driver.findElement(By.id("btnLogin")).click();
   }
 }

Please help me out.

techGaurdian
  • 732
  • 1
  • 14
  • 35
Khushali
  • 5
  • 1
  • 1
  • 2
  • Sheet which package your using can you tell .now i will try – Sathiyaraj Mar 27 '14 at 14:02
  • 2
    Reading excel file has nothing to do with selenium webdriver. Separate your code and _first_ ensure that you can read data from the excel file into the `username` and 'password' variables. – Faiz Mar 27 '14 at 22:24
  • If you are asking about the log4j Warning, I suspect this is a duplicate : http://stackoverflow.com/questions/12532339/no-appenders-could-be-found-for-loggerlog4j – rjdkolb Nov 16 '15 at 13:13
  • I think if you fix log4j as @JpR suggests, you will see some logs to help you. – rjdkolb Nov 16 '15 at 13:17

5 Answers5

1
package com.test.utitlity;

import java.io.IOException;

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;

public class readExcel extends globalVariables {

    /**
     * @param args
     * @throws IOException 
     */
    public static void readExcel(int rowcounter) throws IOException{

        XSSFWorkbook srcBook = new XSSFWorkbook("./prop.xlsx");     
        XSSFSheet sourceSheet = srcBook.getSheetAt(0);
        int rownum=rowcounter;
        XSSFRow sourceRow = sourceSheet.getRow(rownum);
        XSSFCell cell1=sourceRow.getCell(0);
        XSSFCell cell2=sourceRow.getCell(1);
        XSSFCell cell3=sourceRow.getCell(2);
        System.out.println(cell1);
        System.out.println(cell2);
        System.out.println(cell3);



}

}
ChanGan
  • 4,254
  • 11
  • 74
  • 135
0

Your problem is that log4j has not been initialized. It does not affect the outcome of you application in any way, so it's safe to ignore or just initialize Log4J, see: How to initialize log4j properly?

Community
  • 1
  • 1
JpR
  • 19
  • 1
-1

Don't know about what the error you are facing exactly. But log4j:WARN No appenders could be found for logger error, is due to the log4j jar file that you have included in your project.

Initializing log4j is needed but actually Log4j is not necessary for your project. So Right click on your Project → Properties → Java Build Path → Libraries.. Search for log4j jar file and remove it.

Hope it will work fine now.

Sebastien C.
  • 4,649
  • 1
  • 21
  • 32
user2416212
  • 141
  • 1
  • 1
  • 6
-1

i have used following method to use input data from excel sheet: Need to import following as well

import jxl.Workbook;

then

Workbook wBook = Workbook.getWorkbook(new File("E:\\Testdata\\ShellData.xls"));
//get sheet
jxl.Sheet Sheet = wBook.getSheet(0); 
//Now in application i have given my Username and Password input in following way
driver.findElement(By.xpath("//input[@id='UserName']")).sendKeys(Sheet.getCell(0, i).getContents());
driver.findElement(By.xpath("//input[@id='Password']")).sendKeys(Sheet.getCell(1, i).getContents());
driver.findElement(By.xpath("//input[@name='Login']")).click();

it will Work

Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
Amit
  • 23
  • 3
-2
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

String FilePath = "/home/lahiru/Desktop/Sample.xls";
FileInputStream fs = new FileInputStream(FilePath);
Workbook wb = Workbook.getWorkbook(fs);

String <variable> = sh.getCell("A2").getContents();