I want to store username and password in Excel whatever I will type in any application using WebDriver. I am using TestNG framework and Apache POI to write data to Excel. But I am getting Null pointer exception. Please tell me how to work WebDriver with Excel.
public class Test {
private static WebDriver driver;
static String username="abc";
static String password="abf123";
public static void main(String args[]) {
try {
driver.get("any url");
driver.findElement(By.xpath("//*[@id='txtUserName']")).sendKeys(username);
driver.findElement(By.xpath("//*[@id='txtPwd']")).sendKeys(password);
FileOutputStream fos = new FileOutputStream("Userpass.xls");
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet worksheet = workbook.createSheet("POI WorkSheet");
HSSFRow row1 = worksheet.createRow((short) 0);
HSSFCell cell1 = row1.createCell((short) 0);
cell1.setCellValue(username);
HSSFCell cell2 = row1.createCell((short) 1);
cell2.setCellValue(password);
workbook.write(fos);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void f() {
}
}