employer cover photo
employer logo
employer logo

Grepthor Software Solutions

Is this your company?

Grepthor Software Solutions interview question

Read and Write data from Excel in selemiun webdriver?

Interview Answer

Anonymous

24 June 2018

FileInputStream file=new FileInputStream("C:\\Users\\admin\\Desktop\\kkr123.xlsx"); XSSFWorkbook wb=new XSSFWorkbook(file); XSSFSheet ws=wb.getSheet("Sheet1"); int rowCount=ws.getLastRowNum(); for(int i=0;i<=rowCount;i++) { Row r=ws.getRow(i); String linkname=r.getCell(0).getStringCellValue(); try { Thread.sleep(3000); driver.findElement(By.linkText(linkname)).click(); String acturl=driver.getCurrentUrl(); r.createCell(2).setCellValue(acturl); String expurl=r.getCell(1).getStringCellValue(); if(expurl.equals(acturl)) { r.createCell(3).setCellValue("Passed"); } else { r.createCell(3).setCellValue("Failed"); } driver.navigate().back(); } catch(Exception e) { r.createCell(3).setCellValue("Link not found"); } } FileOutputStream f=new FileOutputStream("C:\\Users\\admin\\Desktop\\kkr123.xlsx"); wb.write(f); wb.close(); }