Selenium WebDriver’s driver (i.e. browser driver) is required to make a direct calls to the browser using browser’s native support for automation.
In selenium, FirefoxDriver, InternetExplorerDriver, ChromeDriver and HtmlUnitDriver is a class which implements WebDriver interface.
Selenium WebDriver’s Driver For Different Browsers
1. Firefox Driver: Let’s see how to create Firefox browser’s driver object -
WebDriver driver =
new
FirefoxDriver();
2. Chrome Driver: Let’s see how to create Chrome browser’s driver object -
WebDriver driver = new ChromeDriver();
3. Internet Explorer Driver: Let’s see how to create Internet Explorer browser’s driver object -
WebDriver driver = new InternetExplorerDriver();
4. HtmlUnit Driver: Let’s see how to create HtmlUnit browser’s driver object -
WebDriver driver = new HtmlUnitDriver();
Selenium WebDriver’s Driver Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class SeleniumDriver { public static void main(String[] args) { // Create object of the Firefox driver WebDriver driver = new FirefoxDriver(); // Open Google driver.get("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter text to search for element.sendKeys("Selenium!"); } }