Wednesday 23 November 2011

Data Driven using Excel Data W/O oledb driver in selenium webdriver with CSharp

for (int i = 2; i <= 4; i++)
{
driver.Navigate().GoToUrl(baseURL);
driver.FindElement(By.LinkText("REGISTER")).Click();
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("D:\\Data.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
username = xlWorkSheet.get_Range("A" + i, "A" + i).Value2.ToString();
password = xlWorkSheet.get_Range("B" + i, "B" + i).Value2.ToString();xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
driver.FindElement(By.Name("email")).SendKeys(username);
driver.FindElement(By.Name("password")).SendKeys(password);
}

No comments:

Post a Comment