How can I use HTML Unit Driver as a headless browser with Selenium?

0 votes
Can anyone explain how can I use HTML Unit Driver as a headless browser with Selenium?
May 17 in Selenium by Nishant
272 views

1 answer to this question.

0 votes

Hello @Nishant, follow these steps to use HTML Unit driver as a headless driver with Selenium:

1. 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();
}

}

2. Run the code. You will see that no browser is launched and the result is shown in Console:

answered May 17 by Anvi
• 13,960 points

Related Questions In Selenium

0 votes
1 answer

How can I download Microsoft WebDriver/Edge Driver to use with Selenium?

Hi William, to download Microsoft Webdriver or ...READ MORE

answered Jul 15 in Selenium by Abha
• 27,180 points
719 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
965 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,125 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
868 views
0 votes
1 answer
0 votes
1 answer

How can I write test scripts in Selenium with python?

Hey Khushi, writing test scripts in Selenium ...READ MORE

answered May 9 in Selenium by Anvi
• 13,960 points
77 views