title: How to Iterate Through Cells in Excel in Selenium
body: <p>I am using selenium webdriver to register my application.. </p>
  
  <p><img src="https://i.stack.imgur.com/JdBu4.png" alt="enter image description here"></p>
  
  <p>Now I wanted take the values of username, password, confirm password, email and telephone number. I have used for loop to iterate this.. But when app grows, the fields are added more on the same page. I have to change again the limit value in for loop..</p>
  
  <p>Can I use Iterator to check for a row, if the cell is empty, it should stop and control should be given to the testCase..</p>
  
  <p>Can any one let me know how to use Iterator for this???</p>
  
  <pre><code>package com.xcha.selenium.utitlity;
  
  import java.io.IOException;
  import java.util.ArrayList;
  
  import org.apache.poi.xssf.usermodel.XSSFRow;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class ReadExcel extends GlobalVariables {
  
      /**
       * @param args
       * @throws IOException
       */
      public static ArrayList readExcel(int rowcounter) throws IOException {
  
          XSSFWorkbook srcBook = new XSSFWorkbook("./prop.xlsx");
          XSSFSheet sourceSheet = srcBook.getSheetAt(0);
          int rownum = rowcounter;
          XSSFRow sourceRow = sourceSheet.getRow(rownum);
          int lastcellNum = sourceRow.getLastCellNum() - 1;
          int lastrowNum = sourceSheet.getLastRowNum() - 1;
  
          ArrayList&lt;String&gt; rowValues = new ArrayList&lt;String&gt;();
  
          for (int i = 0; i &lt;= lastcellNum; i++) {
              String val = (sourceRow.getCell(i)).getRichStringCellValue()
                      .getString();
              System.out.println(val);
              rowValues.add(val);
          }
  
          System.out.println("Printing Arraylist");
          for (String strVal : rowValues) {
              System.out.println(strVal);
          }
          return rowValues;
  
      }
  }
  </code></pre>