title: How to read all the rows of the excel sheet and run in Selenium test script using C#?
body: <p>I need help reading all the rows from excel sheet as a test data in my selenium test case.</p>
  
  <p>I can read only one row of an excel sheet with the following code.</p>
  
  <p>//set up test for selenium</p>
  
  <pre><code> public void SetupTest()
      {
          selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com/");
          selenium.Start();
          verificationErrors = new StringBuilder();
      }
  </code></pre>
  
  <p>//Connects me to my excel sheet which is SampleTestData.xls</p>
  
  <pre><code>public void ConnectExcel()
  {
   excel.Application excelApp = new excel.Application();
   excelApp.Visible = true;
   string ExcelDataPath = @"C:\SampleTestData.xls";
   excel.Workbook excelWorkBook = excelApp.Workbooks.Open(ExcelDataPath, 0, false, 5, "", "", false, excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
   excel.Sheets excelSheets = excelWorkBook.Worksheets;
   excel.Worksheet DataworkSheet = (excel.Worksheet)excelSheets.get_Item("Sheet1");
   System.String Search1 = ((excel.Range)DataworkSheet.get_Range("A1", Type.Missing)).Value2 as string;
   }
  </code></pre>
  
  <p>//selenium code to run the test</p>
  
  <pre><code>public void StartTest()
  {
  selenium.open("");
  selenium.WaitForPageToLoad("100000");
  selenium.Type("gbqfif", search1);
  selenium.Click("btnG");
  selenium.WaitForPageToLoad("100000");
  
  }
  </code></pre>
  
  <p>This code lets me select only one row that contains value of search1. However, I need to iterate it such a way that it will keep running StartTest() method until all the rows(50) in the excel sheet are entered.</p>
  
  <p>Any help would be appreciated.</p>