Cannot get a text value from a numeric cell “Poi”

前端 未结 11 2081
余生分开走
余生分开走 2020-12-07 22:17

I\'m trying to consume data from a spreadsheet in Excel, but always of this error, already tried formatting the worksheet to text and number and still the error persists.

11条回答
  •  清歌不尽
    2020-12-07 23:15

    This will work:

    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++){
    
                HSSFCell j_username = sheet.getRow(i).getCell(0)
                HSSFCell j_password = sheet.getRow(i).getCell(0)
    
                //Setting the Cell type as String
                j_username.setCellType(j_username.CELL_TYPE_STRING)
                j_password.setCellType(j_password.CELL_TYPE_STRING)
    
                searchbox.sendKeys(j_username.toString());
                searchbox2.sendKeys(j_password.toString());
    
    
                searchbox.submit();       
    
                driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
    
        }
    
          workbook.close();
          file.close();
    
         } catch (FileNotFoundException fnfe) {
          fnfe.printStackTrace();
         } catch (IOException ioe) {
          ioe.printStackTrace();
         }
    

提交回复
热议问题