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.
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.
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?
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();
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);
}
}
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
Source: Stackoverflow.com