
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Does Selenium support 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.
- Related Questions & Answers
- Does Selenium support Safari browser?
- Selenium testing without browser.
- Browser Plugin Testing With Selenium.
- Does cypress support api automation testing also?
- Selenium and Headless Environment.
- Python class browser support
- Ember.js browser support with HTML
- How does selenium interact with the Web browser?
- Downloading with chrome headless and selenium.
- Does Selenium RC has separate drivers for each browser?
- How does selenium webdriver upload files to the browser?
- Does Python support polymorphism?
- How to connect to Chromium Headless using Selenium?
- Does MySQL support table inheritance?
- Does Python support multiple inheritance?