Selenium with C# Beginners Tutorial | Selenium Testing Tutorials

Orange TechnoMind 27-Sep-2019
orange technomind

Introduction to Selenium with C#

As many people started to work with Selenium. Selenium with C# is another language binding of Selenium WebDriver. There are few other major language bindings with Selenium like Ruby, python, Javascript.

IWebDriver in C#

The IWebDriver is an interface which is used for testing and represents an idealized web browser. The methods are fall into three categories:

  • Control of the browser itself
  • Selection of IWebElements
  • Debugging aids

IWebDriver Browser Commands in C#

CurrentWindowHandle Method

Gets the current window handle, which is a current focused browser window that uniquely identifies it within this driver instance.

PageSource Method

Gets the source of the page remaining loaded through the browser.

Title Method  

Gets the title of the current browser window.

Url Method

Gets or sets the URL the browser which is currently displaying.

WindowHandles Method

Gets the window handles of open browser windows.

Quit Method

This method Closes all windows opened by the IWebDriver.

Close Method

This method Closes the current window opened by the IWebDriver.

Browser Navigation Methods in C#

The INavigation interface exposes the ability to move backwards and forwards in the browser’s history.

GoToUrl Method

This Method is used to navigate to a particular page

Example :  driver.Navigate().GoToUrl("");

Back Method

Back Method is used navigate to the previous page in the browser history. This is similar to click on the back button in your browser.

Example :  driver.Navigate().Back();

Forward Method

Forward Method is used to navigate to the next page in the browser history.This is similar to click on the Forward button in your browser.

Example : driver.Navigate().Forward();

Refresh Method

This Method refreshes the page as if you have pressed F5 on the browser.

Example : driver.Navigate().Refresh();

Locating Elements with WebDriver

  • By ID

IWebElement element = driverOne.FindElement(By.Id("UniqueId"));

  • By Class

IList elements = driverOne.FindElements(By.ClassName("OrangeTechnoMind"));

  • By Tag Name

IWebElement frame = driverOne.FindElement(By.TagName("iframe"));

  • By Name

IWebElement course = driverOne.FindElement(By.Name("OrangeTechnoMind"));

  • By Link Text

IWebElement linkname = driverOne.FindElement(By.LinkText("selenium with C# training in chennai"));

  • By XPath

IList inputs = driverOne.FindElements(By.XPath("//input"));

  • By CSS Selector

IWebElement css = driverOne.FindElement(By.CssSelector("#green"));

IWebElement Methods

Close Method 

Close the contemporary window, quitting the browser if it is the ultimate window currently open.

Dispose Method

Performs application-defined obligations associated with freeing, releasing, or resetting unmanaged resources.

FindElement Method

Finds the first IWebElement using the given method.

FindElements Method

Finds all IWebElements within the current context using the given mechanism.

Manage Method

Instructs the driver to change its settings.

Navigate Method       

Instructs the driver to navigate the browser to every other location.

Quit Method  

Quits this driver, closing every associated window.

SwitchTo Method      

Instructs the driver to send destiny commands to a distinct frame or window.

Difference between FindElement & FindElements Methods






On Zero Match

throws NoSuchElementException

return an empty list


On One Match

returns WebElement


returns list of one WebElement only

On One+ Match

returns the first appearance in DOM

returns list with all matching instance

Types of Alert in Selenium C#

IAlert is an Interface provided by Selenium in the OpenQA.Selenium.IAlert package.The following are the methods

Accept() - It is used to accept the alert

Dismiss() - It is used to dismiss the alert

Text ()- It is used to get the text of the alert

SendKeys() - It is used to write some text to the alert


Are you Looking for Best Selenium Training  in  Chennai with 100% Placement Our accomplished Selenium specialists offer Selenium Training in chennai . Orange TechnoMind provide Selenium Training with practical real-time projects. Free Demo available.




Contact Us

If you have a question, we have an answer. If you need something, we'll help you. Contact us anytime.

For enrollment related queries & support

+91 99 40 550 285

For technical issues & support