Versions used while doing this blog post, (These are the prerequisites to automate chrome browser. Browser and driver versions should match)
selenium .Net version – 4.7.0
chrome browser version – 108
chrome driver version – 108 (Download link : https://chromedriver.chromium.org/downloads) [Selenium manager in latest version auto downloads driver]
Chrome browser can be opened using selenium by following below steps:
1. Instantiate (creation of object) driver object with ChromeDriver() class (This step opens the chrome browser)
IWebDriver driver = new ChromeDriver();
2. Now, next steps of maximizing the browser, setting implicit timeout for driver object and launch of expected website can be carried out
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15); driver.Manage().Window.Maximize(); driver.Navigate().GoToUrl("https://www.google.com");
3. Quit/close the driver object after automating the necessary flows within the website.
driver.quit();
Sample code for reference
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
namespace Selenium4CsharpExamples
{
public class OpenChromeUsingSelenium4
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://www.google.com");
driver.Quit();
}
}
}