How do I use Selenium in C#?

后端 未结 9 935
孤街浪徒
孤街浪徒 2020-12-01 06:38

Selenium.

I downloaded the C# client drivers and the IDE. I managed to record some tests and successfully ran them from the IDE. But now I want to do that using C#. I

9条回答
  •  再見小時候
    2020-12-01 07:29

    Use the below code once you've added all the required C# libraries to the project in the references.

    using OpenQA.Selenium;
    using OpenQA.Selenium.Firefox;
    namespace SeleniumWithCsharp
    {
        class Test
        {
            public IWebDriver driver;
    
    
            public void openGoogle()
            {
                // creating Browser Instance
                driver = new FirefoxDriver();
                //Maximizing the Browser
                driver.Manage().Window.Maximize();
                // Opening the URL
                driver.Navigate().GoToUrl("http://google.com");
                driver.FindElement(By.Id("lst-ib")).SendKeys("Hello World");
                driver.FindElement(By.Name("btnG")).Click();
            }
    
            static void Main()
            {
                Test test = new Test();
                test.openGoogle();
            }
    
        }
    }
    

提交回复
热议问题