Introduction to Selenium
Understand what Selenium is, its architecture, Selenium 4 features, how it compares to other tools, and when to use it.
What is Selenium?
Selenium is the most widely adopted open-source framework for automating web browsers. It supports multiple programming languages, browsers, and operating systems — making it the industry standard for web UI test automation.
Selenium 4 — What's New
Selenium 4 is a major upgrade built on the W3C WebDriver standard. Key improvements include:
- W3C WebDriver Protocol — Direct browser communication, no JSON Wire Protocol translation layer
- Relative Locators — Find elements relative to other elements (above, below, near, toLeftOf, toRightOf)
- Chrome DevTools Protocol (CDP) — Network interception, geolocation mocking, console log capture
- New Window/Tab API — Open new tabs or windows programmatically
- Improved Selenium Grid — Docker support, fully distributed mode, GraphQL queries
Selenium Architecture
Selenium WebDriver communicates directly with the browser through a browser-specific driver (ChromeDriver, GeckoDriver, etc.). Your test code sends commands via the WebDriver API, the driver translates them into browser-native commands, and the browser executes them.
When to Use Selenium
Selenium excels when you need cross-browser testing, multi-language support, a large ecosystem of integrations, or when your team already has Java/Python expertise. It's the right choice for enterprise-scale test automation where flexibility and community support matter.
Tools We'll Use
- Java — Maven for dependency management, TestNG as the test runner, Selenium 4.x WebDriver
- Python — pip for packages, pytest as the test runner, Selenium 4.x bindings
// Java — Selenium 4 Quick Start
// Requires: Maven + Java 17+
// Selenium 4 uses W3C WebDriver protocol natively
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class IntroSelenium {
public static void main(String[] args) {
// Selenium 4 — no need for System.setProperty!
// Selenium Manager auto-downloads the correct driver
WebDriver driver = new ChromeDriver();
try {
driver.get("https://www.selenium.dev/");
System.out.println("Title: " + driver.getTitle());
System.out.println("URL: " + driver.getCurrentUrl());
System.out.println("Browser: Chrome via Selenium 4");
assert driver.getTitle().contains("Selenium");
System.out.println("Selenium 4 is working!");
} finally {
driver.quit();
}
}
}
# Python — Selenium 4 Quick Start
# Install: pip install selenium
from selenium import webdriver
# Selenium 4 — Selenium Manager handles driver automatically!
# No need for webdriver_manager or manual driver downloads
driver = webdriver.Chrome()
try:
driver.get("https://www.selenium.dev/")
print(f"Title: {driver.title}")
print(f"URL: {driver.current_url}")
print("Browser: Chrome via Selenium 4")
assert "Selenium" in driver.title
print("Selenium 4 is working!")
finally:
driver.quit()
Written by PV
© 2026 All Rights Reserved