3
I am trying to consume data from a spreadsheet in excel, but always gives this error, already tried to format the spreadsheet for text and for number and even then the error persists.
How do you fix it?
I saw that one person solved using this cell.setCellType(Cell.CELL_TYPE_STRING);
but I don’t know where I should fit this bit in my code.
WebElement searchbox = driver.findElement(By.name("j_username"));
WebElement searchbox2 = driver.findElement(By.name("j_password"));
try {
FileInputStream file = new FileInputStream(new File("C:\\paulo.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
for (int i=1; i <= sheet.getLastRowNum(); i++){
String j_username = sheet.getRow(i).getCell(0).getStringCellValue();
String j_password = sheet.getRow(i).getCell(0).getStringCellValue();
searchbox.sendKeys(j_username);
searchbox2.sendKeys(j_password);
searchbox.submit();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
}
workbook.close();
file.close();
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
Thank you Anthony.
– Paulo Roberto