Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Selenium in C#?

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 added all relevant DLL files (Firefox) to the project, but I don't have the Selenium class. Some Hello, World! would be nice.

like image 456
Steve Marlusci Avatar asked Jun 13 '11 17:06

Steve Marlusci


People also ask

Does C support Selenium?

> Selenium WebDriver supports various programming languages like Java, Python, C#, Ruby, Perl, PHP, JavaScript, R, Objective-C and Haskell.

What is Selenium C# used for?

C# is being widely used as a language for Selenium Test Automation because you can easily write your test scripts with the help of Visual Studio, which offers access to features like, IntelliSense, debugging, basic refactors, etc.


1 Answers

From the Selenium Documentation:

using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;

class GoogleSuggest
{
    static void Main(string[] args)
    {
        IWebDriver driver = new FirefoxDriver();

        //Notice navigation is slightly different than the Java version
        //This is because 'get' is a keyword in C#
        driver.Navigate().GoToUrl("http://www.google.com/");
        IWebElement query = driver.FindElement(By.Name("q"));
        query.SendKeys("Cheese");
        System.Console.WriteLine("Page title is: " + driver.Title);
        driver.Quit();
    }
}
like image 90
Nathan DeWitt Avatar answered Sep 22 '22 05:09

Nathan DeWitt