How to use Selenium headless

In Java and Python, this merely requires using a headless browser like PhantomJS.

Java

import org.openqa.selenium.phantomjs.PhantomJSDriver;
Webdriver driver = new PhantomJSDriver();

Python

from selenium import webdriver
driver = webdriver.PhantomJS()

C#

The PhantomJS classes are no longer supported in C#, so you need to use Firefox or Chrome in headless mode instead.

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
IWebDriver driver;
FirefoxOptions options = new FirefoxOptions();
options.AddArguments("--headless");
driver = new FirefoxDriver(options);