Chapter{2}: Selenium Automation Testing: Understanding Browser Drivers & Essential Commands

Automate This. By Mrigank Saxena
3 min readJan 31, 2025

--

Image by freepik

This article will break down all the basic Selenium concepts in the simplest way possible — so even if you’ve never coded before, you’ll walk away feeling like a Selenium pro.

What Are Browser Drivers? Why Do We Need Them?

Imagine you have a remote control (Selenium) and a bunch of TVs (different browsers like Chrome, Firefox, Edge).

The problem? Every TV brand uses a different type of remote sensor.

To fix this, you need a driver that acts as a bridge between Selenium and the browser.

Here are the main ones:

ChromeDriver (For Google Chrome)

  • Allows Selenium to control Google Chrome.
  • Uses WebDriver to interact with the browser.
  • Example setup (with WebDriverManager, no manual download needed):
WebDriverManager.chromedriver().setup();   
WebDriver driver = new ChromeDriver();

GeckoDriver (For Mozilla Firefox)

  • Used to automate Firefox.
  • Works the same way as ChromeDriver but for Firefox.
  • Example:
WebDriverManager.firefoxdriver().setup();   
WebDriver driver = new FirefoxDriver();

EdgeDriver (For Microsoft Edge)

  • Controls Microsoft Edge.
  • Example:
WebDriverManager.edgedriver().setup();   
WebDriver driver = new EdgeDriver();

Each of these browser drivers implements the WebDriver interface, meaning they follow the same rules but provide browser-specific implementations.

Essential Selenium Commands

Now that we’ve set up our WebDriver, let’s go over the essential commands used to control the browser.

Opening a Website: driver.get(url) vs driver.navigate().to(url)

Both commands open a webpage, but there’s a small difference:

driver.get("https://www.google.com");
driver.navigate().to("https://www.google.com");

Difference?

  • driver.get(url): Opens the webpage and waits until it fully loads before proceeding.
  • driver.navigate().to(url): Doesn’t wait for full loading, which can be useful for faster automation.

Navigating Between Pages

Selenium also lets you navigate like a human — clicking back, forward, and refreshing the page.

Go Back to the Previous Page

driver.navigate().back();

Just like clicking the back button on a browser.

Go Forward to the Next Page

driver.navigate().forward();

Like clicking the forward button if you’ve gone back.

Refresh the Current Page

driver.navigate().refresh();

Same as pressing F5 on your keyboard.

Finding Elements on a Page

To interact with a website (click buttons, type in search bars, etc.), Selenium needs to find elements first.

Using ID

driver.findElement(By.id("searchBox"));

Finds an element with the ID “searchBox”.

Using Name

driver.findElement(By.name("username"));

Finds an element with the name attribute “username”.

Using XPath (For Complex Locators)

driver.findElement(By.xpath("//button[@id='submit']"));

Finds a button with the ID “submit” using XPath (which we’ll cover in the next article — for now, just think of it as the address of a web element, like a “submit” button on a web page).

Putting It All Together: A Simple Test Script

Here’s a basic Selenium script that:

  1. Opens a browser.
  2. Goes to Google.
  3. Prints the page title.
  4. Closes the browser.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;

public class SeleniumExample {
public static void main(String[] args) {
// Automatically setup ChromeDriver
WebDriverManager.chromedriver().setup();

// Initialize WebDriver
WebDriver driver = new ChromeDriver();

// Open Google
driver.get("https://www.google.com");

// Print the page title
System.out.println("Title: " + driver.getTitle());

// Close the browser
driver.quit();
}
}

Final Thoughts

Understanding browser drivers and essential Selenium commands is the first step to automating websites.

  • Browser drivers (ChromeDriver, GeckoDriver, EdgeDriver) are necessary for Selenium to interact with browsers.
  • Basic commands like get(), navigate().to(), navigate().back(), and findElement() help control the browser.
  • WebDriverManager makes setup easier by handling driver downloads automatically.

Now that you have the foundation, you’re ready to start writing more advanced Selenium scripts!

You can find and download the code here.

You can now catch the podcast on YouTube too!

.

.

.

Happy Coding!

--

--

Automate This. By Mrigank Saxena
Automate This. By Mrigank Saxena

Written by Automate This. By Mrigank Saxena

Join me as I share insights, tips, and experiences from my journey in quality assurance, automation, and coding! https://www.linkedin.com/in/iammriganksaxena/

No responses yet