Friday, 24 January 2014

How to launch the chrome browser using selenium in C#?

It is very simple to start the chrome browser and start performing the operations on it.
You can first read about how to set up the selenium web driver in visual studio.

Example -
Source code to automate the chrome browser is given below.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{


//Below line of code will create a new instance of the chrome browser
IWebDriver x = new ChromeDriver(@"C:\Users\sagar\Downloads");


//Below line sets the url property of the driver object.
x.Url = "http://register.rediff.com/commonreg/index.php";


//Here we are calling navigate method to open the website in browser
x.Navigate();


//Below line will find the element with id "fullname" and then enter the text "salunke saheb" into it.
x.FindElement(By.Id("fullname")).SendKeys ("Salunke Saheb");


x.Navigate();
x.FindElement(By.Id("fullname")).SendKeys ("salunke");



x.Quit();

}
}
}


This is how we can start the chrome browser in C# using selenium API.


What do you think on above selenium topic. Please provide your inputs and comments. Thanks

No comments:

Post a Comment

Buy Best Selenium Books

About Me

My photo

Self-motivated software professional