title: How do I use cell values from an Excel worksheet as input?
body: <p>I need to write a code that will go through a sheet of an Excel file (.xlsx)
  and then use those values from the cell one by one via WebDriver.</p>
  
  <p>To be more specific, one sheet holds search engines links and another sheet holds queries.</p>
  
  <p>I only need you to help me figure out how to use the links from the Excel file, 
  and not as hard coded values, a way to iterate through them.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>package a.utilities;
  
  import java.awt.List;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.*;
  
  import a.utilities.ChromeDriverInit;
  
  import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.ss.usermodel.Sheet;
  import org.apache.poi.ss.usermodel.Workbook;
  import org.apache.poi.ss.usermodel.WorkbookFactory;
  import org.apache.poi.*;
  import org.apache.poi.xssf.usermodel.XSSFCell;
  import org.apache.poi.xssf.usermodel.XSSFRow;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  import org.openqa.selenium.WebDriver;
  
  public class ExcelUtils {
      static WebDriver driver;
      protected static XSSFSheet excelWSheet;
      protected static XSSFWorkbook excelWBook;
      private static XSSFCell cell;
      private static XSSFRow row;
      //
      static String web;
      static String query;
  
      // Setting the file to read from
      public static void setExcelFile() throws FileNotFoundException {
          FileInputStream file = null;
  
          try {
              file = new FileInputStream("ExcelWorkSheets/SearchEngines.xlsx");
              excelWBook = new XSSFWorkbook(file);
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
  
          } finally {
              if (file != null) {
                  try {
                      file.close();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
  
      }
  
      // Counting the used rows in every work sheet and give you the work sheets data
      public static void getSheetData() {
          int index = 0;  
          for (int i = 0; i &lt; excelWBook.getNumberOfSheets(); i++) {
              index++;
              System.out.println("Sheet Name: " + "["
                      + excelWBook.getSheetName(i) + "] --&gt; " + "Sheet index: "
                      + "[" + index + "]\n");
  
          }
          int rowIndex = 0;
          for (int i = 0; i &lt; excelWBook.getSheetAt(0).getLastRowNum()+1; i++) {
              excelWSheet = excelWBook.getSheetAt(0);
              rowIndex++;
  
          }
          System.out.println("Number of rows including the header: --&gt; " + rowIndex);
          System.out.println("Number of rows not including the header: --&gt; " +excelWSheet.getLastRowNum());
          System.out.println();
  
  
          int rowIndex2 = 0;
          for (int i = 0; i &lt; excelWBook.getSheetAt(1).getLastRowNum()+1; i++) {
              excelWSheet = excelWBook.getSheetAt(1);
              rowIndex2++;
  
          }
          System.out.println("Number of rows including the header: --&gt; " + rowIndex2);
          System.out.println("Number of rows not including the header: --&gt; " +excelWSheet.getLastRowNum());
          System.out.println();
  
  
      // Going through the SearchEngines work sheet to get the data from every used cell and prints it out
  
          Iterator&lt;Row&gt; rowIterator = excelWSheet.iterator();
          while(rowIterator.hasNext()) {
              Row row = rowIterator.next();
  
              Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
              while(cellIterator.hasNext()) {
  
                  Cell cell = cellIterator.next();
  
                  switch (cell.getCellType()) {
                  case Cell.CELL_TYPE_BOOLEAN:
                      System.out.println(cell.getBooleanCellValue() + "\t\t");
                      break;
                  case Cell.CELL_TYPE_NUMERIC:
                      System.out.println(cell.getNumericCellValue() + "\t\t");
                  case Cell.CELL_TYPE_STRING:
                      web = cell.getStringCellValue();
                      System.out.println(web + "\t\t");
  
                  default:
                      break;
                  }
              }
              System.out.println("");
          }
          // Going through the queries work sheet to get the data from every used cell and prints it out
          Iterator&lt;Row&gt; rowIterator2 = excelWSheet.iterator();
              while(rowIterator2.hasNext()) {
                  Row row = rowIterator2.next();
  
                  Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
                  while(cellIterator.hasNext()) {
  
                      Cell cell = cellIterator.next();
  
                      switch (cell.getCellType()) {
                      case Cell.CELL_TYPE_BOOLEAN:
                          System.out.println(cell.getBooleanCellValue() + "\t\t");
                          break;
                      case Cell.CELL_TYPE_NUMERIC:
                          System.out.println(cell.getNumericCellValue() + "\t\t");
                          break;
                      case Cell.CELL_TYPE_STRING:
                          System.out.println(cell.getStringCellValue() + "\t\t");
                          break;
  
                      default:
                          break;
                      }
                  }
                  System.out.println("");
              }
      }        
  </code></pre>
  
  <p>This does go through the list, but how do I pass it on so WebDriver would be able to use this values?</p>