First Automation Program
Let us kick start automating our first program.
Program: To open www.google.com in chrome browser.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace First_Program
{
class Program
{
static void Main(string[] args)
{
//Creates an instance of chrome browser
IWebDriver chrome = new ChromeDriver();
//Opens www.google.com in chrome browser
chrome.Navigate().GoToUrl("https://www.google.com");
}
}
}
Now let us analyse the above program:- Importing Packages in Namespace Section
- OpenQA.Selenium - Contains the WebDriver class needed to instantiate a new browser loaded with a specific driver
- OpenQA.Selenium.Chrome - Contains the chromeDriver class needed to instantiate a chrome-specific driver onto the browser instantiated by the WebDriver class.
- The following namespace are specific to browser:
- using OpenQA.Selenium.Edge; //Used for Edge browser
- using OpenQA.Selenium.IE; //Used for IE Browser
- using OpenQA.Selenium.firefox; //Used for firefox browser
- using OpenQA.Selenium.Opera; // Used for Opera browser
- Main Program:
- Iwebdriver is an interface through which user controls the browser.
IWebDriver chrome = new ChromeDriver();
//The above statement creates a new instance of google chrome browser. Syntax to create a new instance of various browser:- - IWebDriver IE = new InternetExplorerDriver();//For IE Explorer
- IWebDriver fox = new FirefoxDriver();//For Morzilla firefox
- IWebDriver edge = new EdgeDriver();//For Edge browser
- chrome.Navigate().GoToUrl("Https://www.google.co.in");
The navigate method instructs the browser to navigate to another location. - GoToUrl(string) method loads a webpage in the current browser window.
We finally finished Automating our first program.
In the next Tutorial let us learn more about navigation command!
No comments:
Post a Comment