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, 2019 in Selenium by Nishant
4,281 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, 2019 by Anvi
• 14,150 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, 2019 in Selenium by Abha
• 28,140 points
40,992 views
0 votes
1 answer

How can I travel forward and back in a browser using selenium?

You can use the Navigate interface to ...READ MORE

answered Dec 31, 2018 in Selenium by Nabarupa
12,282 views
0 votes
1 answer

How can I add Cucumber Jar files in Eclipse to use with Selenium Webdriver?

Hey Eshan, follow these steps to add ...READ MORE

answered May 23, 2019 in Selenium by Abha
• 28,140 points
5,999 views
0 votes
1 answer

How can I perform mouse hover to a web element with ruby and selenium webdriver?

Hi Siddhart, checkout the following script to ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 28,140 points
2,612 views
0 votes
2 answers

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,500 points
13,773 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,188 views
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,910 points
7,263 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,902 views
0 votes
1 answer

How can I refresh a browser window in different ways using Selenium Webdriver?

Hello Piyush, you can refresh a browser ...READ MORE

answered May 29, 2019 in Selenium by Anvi
• 14,150 points
3,257 views
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, 2019 in Selenium by Anvi
• 14,150 points
915 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP