Simple Code with Selenium C#

Here’s a short but sweet article on using C# with Selenium.

by Karthik KK

The author is easy to read and apply his approaches.

Simple Code with Selenium C#

In this post we will discuss writing some simple code with Selenium C# in Visual Studio IDE. In the last post we referenced our Selenium WebDriver and Chrome driver via Nuget package manager in our project. Please read my previous post to get started with selenium referencing in Visual Studio IDE.

Once you are done with setup (referencing), you are all set you write a simple code.

Here is the code snippet:

  1. “//Create the reference for our browser
  2. IWebDriver driver = new ChromeDriver();
  3. //Navigate to google page
  4. driver.Navigate().GoToUrl(“”);
  5. //Find the Search text box UI Element
  6. IWebElement element = driver.FindElement(By.Name(“q”));
  7. //Perform Ops
  8. element.SendKeys(“executeautomation”);
  9. //Close the browser
  10. driver.Close();”In the above code snippet, we have

Created an instance for IWebDriver and got the instance for ChromeDriver
Navigate to Google home page
Found the Search textbox of google home page
Searched for execute automation by typing the text
Close the driver instance (which closes the chrome browser)

Here is the complete video for the above explanation

Video 1 – Introduction
Intro to Selenium with C#
(NOTE: There are 3 more videos following this intro. All Good! Webmaster-Bill)

Thanks for watching the video and reading the post !!

Please leave your comments and let me know if there is anything need to be improved in the post !!!

Karthik KK