
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Selenium Support for Headless Browser Testing
Yes, Selenium supports headless browser testing. This can be done with the help of the HTMLUnitDriver. It is the fastest webdriver among other browser drivers and is platform independent.
After Selenium 2.53 version, HTMLUnitDriver jar has to be added explicitly within the project. To add the dependency, follow the steps as listed below −
Navigate to the link − https://github.com/SeleniumHQ/htmlunitdriver/releases.
Click on the link highlighted in the below image.
Right-click on the project and choose Build path. Then click on Configure Build Path.
Go to Java Build Path, then select Libraries. Click on Add External JARs. Then browse and add the HTMLUnitDriver jar.
We have to add org.openqa.selenium.htmlunit.HtmlUnitDriver to the project.
Example
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 HeadlessMode{ public static void main(String[] args) { //HtmlUnitDriver initialization HtmlUnitDriver driver = new HtmlUnitDriver(); driver.get("https://www.tutorialspoint.com/questions/index.php"); // wait of 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); System.out.println("Page title: " + driver.getTitle()); } }
Output
Also, there will be no browser displayed as execution goes on.