What is Selenium WebDriver?
Selenium WebDriver (also called Selenium 2) is the current standard for browser automation. Unlike Selenium RC, it communicates directly with the browser through native browser APIs.
Key points:
1. Browser Automation Framework: WebDriver accepts test commands and sends them directly to the browser — no intermediate JavaScript injection required.
WebDriver driver = new ChromeDriver();
driver.get("https://example.com"); // Command sent to Chrome
driver.findElement(By.id("btn")).click(); // Chrome executes native click
2. Implemented Through Browser-Specific Drivers: Each browser has its own driver that implements the WebDriver protocol.
| Browser | Driver |
|---|---|
| Chrome | ChromeDriver |
| Firefox | geckodriver |
| Edge | EdgeDriver |
| Safari | SafariDriver |
| IE | IEDriverServer |
3. Direct Browser Communication: WebDriver communicates using the W3C WebDriver Protocol (HTTP-based JSON Wire Protocol) — direct, native, and fast.
Java Test → ChromeDriver → Chrome Browser
(W3C commands) (native)
4. Language Support:
Java, C#, Python, Ruby, JavaScript (Node.js), PHP, Perl
Architecture:
// These are all valid WebDriver implementations
WebDriver driver = new ChromeDriver(); // Chrome
WebDriver driver = new FirefoxDriver(); // Firefox
WebDriver driver = new EdgeDriver(); // Edge
WebDriver driver = new RemoteWebDriver(...); // Selenium Grid
WebDriver vs Selenium RC:
| Feature | Selenium RC | Selenium WebDriver |
|---|---|---|
| Communication | JavaScript injection | Direct W3C protocol |
| Speed | Slower | Faster |
| Security restrictions | Has same-origin limits | No restrictions |
| Architecture | Server required | Direct driver connection |
| Current status | Maintenance mode | Active standard |
Key points:
- ✓WebDriver is a browser automation framework that accepts commands and sends them to a browser
- ✓Implemented through browser-specific drivers (ChromeDriver, geckodriver, etc.)
- ✓Controls the browser by directly communicating with it
- ✓Supports: Java, C#, PHP, Python, Perl, Ruby
