How to Run a Headless Chrome Browser in Selenium WebDriver

How to Run a Headless Chrome Browser in Selenium WebDriver

Starting with version 60, the Chrome browser introduced the ability to run in headless mode. Learn how to run a headless Chrome browser in Selenium WebDriver. This will allow you to run tests faster and with fewer resources, and most importantly, it will allow you to run tests on systems without a graphical component. Don’t worry — the ability to take screenshots won’t be affected in any way.

Starting with version 60, the Chrome browser introduced the ability to run in headless mode. We now have the ability to launch the browser without creating a visual browser window. This will allow you to run tests faster and with fewer resources, and most importantly, it will allow you to run tests on systems without a graphical component. Don’t worry — the ability to take screenshots won’t be affected in any way.

In this article, I want to demonstrate how you can use this functionality.

The beginning of any auto test starts as standard, we specify the path to our chrome driver:

System.setProperty("webdriver.chrome.driver", "/path/to/driver");

After this thing, we have to do is to create a WebDriver object, and set the ChromeDriver path and some arguments :

ChromeOptions options = new ChromeOptions();options.addArguments("--headless");WebDriver driver = new ChromeDriver(options);

That is all. You can run it.

However, there is one problem. The invisible browser window is only 800x600 in size. Therefore, you need to set the desired screen size with an additional argument:

ChromeOptions options = new ChromeOptions();options.addArguments("--headless", "--window-size=1920,1200");WebDriver driver = new ChromeDriver(options);

As a rule, you should also specify disabling GPU rendering, extensions, and disabling pop-up extensions in developer mode. This usually results in very ugly and unreadable code.

ChromeOptions options = new ChromeOptions();options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors","--disable-extensions","--no-sandbox","--disable-dev-shm-usage");WebDriver driver = new ChromeDriver(options);

google-chrome selenium testing web-development developer

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

Hire Dedicated eCommerce Web Developers | Top eCommerce Web Designers

Build your eCommerce project by hiring our expert eCommerce Website developers. Our Dedicated Web Designers develop powerful & robust website in a short span of time.

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Custom Web Development Services | Vinew Technologies

Vinew Technologies is the leading Custom web development services company known for creating state of the art custom business websites that help you engage your audience better.