How to take data from Excel with Selenium

Viewed 32

I created 2 classes , the first is main and the srcond for functions of seleium, i want to add to Functions class method which takes data from excel, any idea how to do that? I have excel file in the project. I tried to use with solution from google but without success

//Functios class

  public Functions(IWebDriver driver)
        {
            this.driver = driver;
        }

        public void OpenBrowser()
        {

            driver.Navigate().GoToUrl("https://www.google.com/");
        }

        public void existsElement(string element)
        {
              driver.FindElement(By.Id(element));       
        }

        public void Click(string cssselector)
        {
            driver.FindElement(By.Id(cssselector)).Click();
            
        }
        public void Set(string cssselector)
        {
            driver.FindElement(By.Id(cssselector)).SendKeys("abc123@abc123.com");//Here i want insert data from Excel

        }
    }

//Main class

  public class UnitTest1

    {
        [TestMethod]
        public void TestMethod1()
        {
            IWebDriver driver = new EdgeDriver();
            driver.Manage().Window.Maximize();
            Functions f = new Functions(driver);
            f.OpenBrowser();
            f.existsElement("header_logo");
            f.Click("contact-link");
            f.Set("email_create");
            f.Click("SubmitCreate");
            f.existsElement("center_column");
        }
    }
0 Answers
Related