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
30 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
• 9,950 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 1 day ago in Selenium by Abha
• 15,680 points
9 views
0 votes
1 answer
0 votes
1 answer
+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
5,008 views
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,050 points
249 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
621 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
243 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
• 9,950 points
27 views