Versions used while doing this blog post, (These are the prerequisites to automate Firefox browser. Browser and driver versions should match)
selenium-java version – 4.7.0
firefox browser version – 106
gecko driver version – 0.31.0 (Download link : https://github.com/mozilla/geckodriver/releases) [Selenium manager in latest selenium auto download the driver version]
Firefox browser can be opened using selenium by following below steps:
1. Instantiate (creation of object) driver object with FirefoxDriver() class (This step opens the firefox browser)
IWebDriver driver = new FirefoxDriver();
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.Firefox;
using System;
namespace Selenium4CsharpExamples
{
public class OpenFirefoxUsingSelenium4
{
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://www.google.com");
driver.Quit();
}
}
}