- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Run WebDriver in Headless Mode using Postman?
We can run webdriver in headless mode. This is achieved with the HTMLUnitDriver which is the fastest webdriver among all the other browser drivers.
Post Selenium 2.53 version, the HTMLUnitDriver jar should be added explicitly in the project. To add the required dependency, the below steps need to be followed −
Navigate to − https://github.com/SeleniumHQ/htmlunit-driver/releases.
Click on the jar marked in the below image.
Right-click on the project and choose the option Build path. Then click on Configure Build Path.
Click on Java Build Path and select the Libraries tab. Click on the Add External JARs button. Then add the downloaded HTMLUnitDriver jar. Finally, click on the Apply and Close button.
In our code, we have to add the import statement org.openqa.selenium.htmlunit.HtmlUnitDriver for the HTMLUnitDriver.
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 HeadlessModeHTMLUnit{ public static void main(String[] args) { //HtmlUnitDriver instance HtmlUnitDriver driver = new HtmlUnitDriver(); // implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.tutorialspoint.com/questions/index.php"); System.out.println("Page title: " + driver.getTitle()); driver.quit(); } }