title: Writing status to Excel file in Java using Selenium WebDriver
body: <p>I am able to write the status to the Excel file through my program, but there is still an issue, the status is not writing correctly to the Excel sheet. The console output is fine -</p>
  
  <blockquote>
    <p>Value of MoulikaNimmala is: Fail  key is:MoulikaNimmala Fail and 1</p>
    
    <p>Value of lakshman_nimmala@yahoo.com is: Pass  key
    is:lakshman_nimmala@yahoo.com Pass and 2</p>
    
    <p>Value of sailakshman.nimmala@gmail.com is: Fail  key
    is:sailakshman.nimmala@gmail.com Fail and 3</p>
    
    <p>Value of Keshav is: Fail  key is:Keshav Fail and 4</p>
  </blockquote>
  
  <p>But the status in the Excel sheet is filling up incorrectly. lakshman_nimmala@yahoo should be filled with Pass and keshav should be filled with Fail.</p>
  
  <pre><code>    @Test(priority = 2)
      public void readData() throws Exception {
      String filePath = System.getProperty("user.dir") + "\\Test Data";
      String fileName = "editSubscriptions.xls";
      String sheetName = "datapool";
  
      File file = new File(filePath + "\\" + fileName);
      FileInputStream fis = new FileInputStream(file);
      Workbook workbook = null;
  
      String fileExtName = fileName.substring(fileName.indexOf("."));
  
      if (fileExtName.equals(".xlsx")) {
          workbook = new XSSFWorkbook(fis);
      } else if (fileExtName.equals(".xls")) {
          workbook = new HSSFWorkbook(fis);
      }
      Sheet sheet = workbook.getSheet(sheetName);
      int rowCount = sheet.getLastRowNum() - sheet.getFirstRowNum();
  
      HashMap&lt;String, String&gt; hm = new HashMap&lt;String, String&gt;();
  
      for (int i = 1; i &lt; rowCount+1; i++) {
          Row row = sheet.getRow(i);
  
              WebDriverWait wait = new WebDriverWait(driver, 10);
              wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='Sign In']")));
              driver.findElement(By.xpath("//*[text()='Sign In']")).click();
  
              WebDriverWait wait1 = new WebDriverWait(driver, 10);
              wait1.until(ExpectedConditions.visibilityOfElementLocated(By.name("username")));
              driver.findElement(By.name("username")).clear();
  
              driver.findElement(By.name("username")).sendKeys(row.getCell(0).toString());
              driver.findElement(By.name("passwd")).clear();
  
              driver.findElement(By.name("passwd")).sendKeys(row.getCell(1).toString());
              driver.findElement(By.name("signin")).click();
              Thread.sleep(10000);
              try {
                  new Actions(driver).moveToElement(driver.findElement(By.xpath("//*[text()='nimmala']"))).perform();
                  driver.findElement(By.xpath("//*[text()='Sign Out']")).click();
  
                  WebDriverWait wait2 = new WebDriverWait(driver, 10);
                  wait2.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='Sign In']")));
                  driver.findElement(By.xpath("//*[text()='Sign In']")).click();
  
                  hm.put(row.getCell(0).toString(), "Pass");
              } catch (Exception ex) {
                  //ex.printStackTrace();
                  hm.put(row.getCell(0).toString(), "Fail");
                  driver.get("http://in.yahoo.com/?p=us");
              }
      }  
  
      Set&lt;String&gt; keys = hm.keySet();
  
      int i=1;
      for (String key: keys){
          System.out.println("Value of "+key+" is: "+hm.get(key));
  
          String filePath1 = System.getProperty("user.dir") + "\\Test Data";
          String fileName1 = "editSubscriptions.xls";
          String sheetName1 = "datapool";
  
          File file1 = new File(filePath1 + "\\" + fileName1);
          FileInputStream fis1 = new FileInputStream(file1);
          Workbook workbook1 = null;
  
          String fileExtName1 = fileName1.substring(fileName1.indexOf("."));
  
          if (fileExtName1.equals(".xlsx")) {
              workbook1 = new XSSFWorkbook(fis1);
          } else if (fileExtName1.equals(".xls")) {
              workbook1 = new HSSFWorkbook(fis1);
          }
          Sheet sheet1 = workbook1.getSheet(sheetName1);
          int rowCount1 = sheet1.getLastRowNum() - sheet1.getFirstRowNum();
  
              Cell cell1 = sheet1.getRow(i).createCell(2);
              cell1.setCellType(Cell.CELL_TYPE_STRING);
              cell1.setCellValue(hm.get(key));
              System.out.println(" key is:" + key+" "+hm.get(key) + " and " + i);
              i = i+1;
  
        //Close input stream
          fis1.close();
  
        //Create an object of FileOutputStream class to create write data in excel file
          FileOutputStream outputStream = new FileOutputStream(file1);
  
          //write data in the excel file
          workbook1.write(outputStream);
  
          //close output stream
          outputStream.close();
      }
    }
  </code></pre>
  
  <p>The problem is with identifying the row index.  </p>
  
  <p>Is there a way for us to identify the row index depending upon the cell value in the Excel file so that I can replace <code>i</code> in the below statement with the correct row index?:</p>
  
  <p><code>Cell cell1 = sheet1.getRow(i).createCell(2);</code></p>