How to Run WebDriver in Headless Mode using Postman?

We can run webdriver in headless mode. This is achieved with the HTMLUnitDriver which is the fastest webdriver among all the other browser drivers.

Post Selenium 2.53 version, the HTMLUnitDriver jar should be added explicitly in the project. To add the required dependency, the below steps need to be followed −

  • Right-click on the project and choose the option Build path. Then click on Configure Build Path.

  • Click on Java Build Path and select the Libraries tab. Click on the Add External JARs button. Then add the downloaded HTMLUnitDriver jar. Finally, click on the Apply and Close button.

  • In our code, we have to add the import statement org.openqa.selenium.htmlunit.HtmlUnitDriver for the HTMLUnitDriver.

Code Implementation

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class HeadlessModeHTMLUnit{
   public static void main(String[] args) {
      //HtmlUnitDriver instance
      HtmlUnitDriver driver = new HtmlUnitDriver();
      // implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      System.out.println("Page title: " + driver.getTitle());