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
7 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 5,960 points

Related Questions In Selenium

0 votes
1 answer
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 2 days ago in Selenium by Abha
• 6,370 points
7 views
+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,030 points
3,998 views
0 votes
1 answer

How do we use Gecko driver.exe with Selenium?

Recently Selenium launched v3 and if you ...READ MORE

answered Apr 7, 2018 in Selenium by nsv999
• 5,030 points
37 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,030 points
71 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
442 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
55 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 in Selenium by Anvi
• 5,960 points
11 views
0 votes
1 answer

How can I create a POM test case in Selenium Webdriver?

Hey Akshay, follow these steps to create ...READ MORE

answered May 12 in Selenium by Anvi
• 5,960 points
17 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.