QA Wiki

Selenium WebDriver

Browser automation framework for web application testing

Active

Overview

Selenium WebDriver is a web framework that allows you to execute cross-browser tests. It provides a programming interface to create and run test cases, giving you the ability to create robust, browser-based regression automation suites and tests.

Key Features

  • Cross-browser testing
  • Multiple language support
  • Handles dynamic web elements
  • Integration with testing frameworks

Supported Languages

Java Python C# Ruby JavaScript Kotlin

Installation

Java Installation

// Maven dependency
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.8.0</version>
</dependency>

// Gradle dependency
implementation 'org.seleniumhq.selenium:selenium-java:4.8.0'

Python Installation

pip install selenium

WebDriver Setup

// Download browser drivers from:
// Chrome: https://sites.google.com/chromium.org/driver/
// Firefox: https://github.com/mozilla/geckodriver/releases
// Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

// Set system property for Java
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

Basic Usage

Java Example

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class FirstTest {
    public static void main(String[] args) {
        // Set the path to chromedriver
        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
        
        // Initialize browser
        WebDriver driver = new ChromeDriver();
        
        // Open Google
        driver.get("https://www.google.com");
        
        // Get and print title
        System.out.println("Page title is: " + driver.getTitle());
        
        // Close browser
        driver.quit();
    }
}

Python Example

from selenium import webdriver
from selenium.webdriver.common.by import By

# Initialize Chrome driver
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')

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

# Find search box and type query
search_box = driver.find_element(By.NAME, "q")
search_box.send_keys("Selenium WebDriver")
search_box.submit()

# Print title
print("Page title is:", driver.title)

# Close browser
driver.quit()

Related Tools

Cypress

JavaScript testing framework

Playwright

Cross-browser automation

TestNG

Testing framework

JUnit

Unit testing framework

Best Practices

Use explicit waits instead of thread.sleep()

Implement Page Object Model pattern

Keep tests independent and atomic

Use proper selectors (ID, CSS, XPath)

Implement proper test reporting

Version Information

Current Version 4.8.0
Release Date March 2023
License Apache 2.0
Browser Support

Made with DeepSite LogoDeepSite - 🧬 Remix