How to open a browser in selenium using c#?

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

Same way we need to add our browser reference.

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

//Create the reference for our browser
IWebDriver driver = new ChromeDriver();

//Navigate to google page
driver.Navigate().GoToUrl("http:www.google.com");

//Find the Search text box UI Element
IWebElement element = driver.FindElement(By.Name("q"));

//Perform Ops
element.SendKeys("executeautomation");

//Close the browser
driver.Close();

In Above code we have :

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s