Can anyone explain how to use HTML Unit Driver as a headless browser with Selenium?
Hi Brett,
Follow the below step to use HTML Unit driver as a headless driver with Selenium:
In Eclipse, copy the following code along with standard selenium library files:
package headlessDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class HtmlDriver {
public static void main(String[] args) {
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Edureka");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}