title: Read data from excel in Selenium Webdriver with c#
body: <p>I am working with selenium webdriver c#. I need to read data from excel.</p>
  
  <p>Code:</p>
  
  <pre><code>using System;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using NUnit.Framework;
  using OpenQA.Selenium;
  using OpenQA.Selenium.Chrome;
  using OpenQA.Selenium.Support.UI;
  using Excel = Microsoft.Office.Interop.Excel;
  
  
  
  namespace UIL
  {
      [TestClass]
      public class UIL_Login : UtilityHelper
      {
          IWebDriver driver;
          Excel.Application loginapp;
          Excel.Workbook loginworkbook;
          Excel._Worksheet loginworksheet;
          Excel.Range loginrange;
  
          public UIL_Login()
          {
              loginapp = new Excel.Application();
              loginworkbook = loginapp.Workbooks.Open(@"D:\\MyProjects\\Selenium_C#\\SeleniumProjects\\UIL\\UIL\\Resources\\login.xls");
              //loginworksheet = loginworkbook.Sheets[1];
              loginworksheet = (Excel.Worksheet)loginworkbook.Worksheets.get_Item(1);
              loginrange = loginworksheet.UsedRange;
          }
  
          [TestInitialize]
          public void SetUp()
          {
              driver = new ChromeDriver(@"D:\\MyProjects\\Selenium_C#\\Selenium\\chromedriver");
              driver.Navigate().GoToUrl("http://192.168.0.35:92");
              driver.Manage().Window.Maximize();
          }
  
          /*Login without username*/
          [TestMethod]
          public void loginWithoutUsername()
          {
              try
              {
                  int emptyUsernameRowNumber = 1;
                  driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1000);
                  IWebElement username = webElement(driver, Constants.VAR_EMAIL);
                  username.Clear();
                  //username.SendKeys("amrutha.u@teamta.in");
                  username.SendKeys(loginrange.Cells[emptyUsernameRowNumber][1]);
                  driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1000);
                  IWebElement password = webElement(driver, Constants.VAR_PASSWORD);
                  password.Clear();
                  // password.SendKeys("UIL@123#");
                  password.SendKeys(loginrange.Cells[emptyUsernameRowNumber][2]);
                  driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1000);
                  IWebElement signinButton = driver.FindElement(By.XPath("//*[@id='mainDiv']/div[4]/div/div/form/a/button"));
                  signinButton.Click();
              }
              catch (Exception e)
              {
                  Console.Write(e);
  
              }
  
          }
      }
  }
  </code></pre>
  
  <p>But i am getting the following exception:</p>
  
  <blockquote>
    <p>Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best
    overloaded method match for
    'OpenQA.Selenium.IWebElement.SendKeys(string)' has some invalid
    arguments    at CallSite.Target(Closure , CallSite , IWebElement ,
    Object )    at
    System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite
    site, T0 arg0, T1 arg1)</p>
  </blockquote>
  
  <p>Can anybody help to solve this issue?</p>