Quickstart: Use Selenium in C#

Heute (update 20.3.2018, Visual Studio 2017)

  • Datei -> Neu -> Projekt
  • Installiert -> Visual C# -> Klassischer Windows-Desktop -> Konsolen-App (.NET Framework)
  • Projekt -> NuGet-Pakete verwalten -> Durchsuchen: ‚Selenium‘ -> Selenium.WebDriver downloaden
  • Download jüngsten Mozilla GeckoDriver here: https://github.com/mozilla/geckodriver/releases
  • Unzip geckodriver.exe into /bin/Debug
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace SeleniumExampleInCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.google.de";
            driver.FindElement(By.Id("lst-ib")).SendKeys("IT Kosmopolit");
            driver.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
        }
    }
}

 
Früher

  • In Visual Studio: Project -> New -> Console Project
  • Download C#-Selenium client here: http://www.seleniumhq.org/download/
  • Create references to all .dlls there
  • Download Mozilla GeckoDriver here: https://github.com/mozilla/geckodriver/releases/tag/v0.11.1
  • Unzip geckodriver.exe into /bin/Debug
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace SeleniumExampleInCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.google.de";
            driver.FindElement(By.Id("lst-ib")).SendKeys("Projektfisch");
            driver.FindElement(By.ClassName("sfsbc")).Click();
        }
    }
}