0

How do I open a Firefox browser in headless mode using Selenium ?

2
  • 2
    Please share the research you have done and the issues you faced. Try to use google first, there are numerous posts on that.
    – Alexey R.
    Commented Oct 19, 2017 at 9:54
  • Please read the Help section, especially sqa.stackexchange.com/help/how-to-ask, then edit your question to tell us what you have tried, what version of Firefox you are trying to use, what version of Selenium you are trying to use, the code you've tried, and any error messages you're receiving.
    – Kate Paulk
    Commented Oct 19, 2017 at 11:28

2 Answers 2

0

This is built-in to Firefox and released on September 28, 2017 (FF56.0)

Headless Firefox works on Fx55+ on Linux, and 56+ on Windows/Mac.

The Firefox team has usage examples on their Headless documentation page.

Their NodeJS example:

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var firefox = require('selenium-webdriver/firefox');
var binary = new firefox.Binary(firefox.Channel.NIGHTLY);
binary.addArguments("-headless");

var driver = new webdriver.Builder()
    .forBrowser('firefox')
    .setFirefoxOptions(new firefox.Options().setBinary(binary))
    .build();

In summary it is taking a binary that supports headless and adding the -headless argument to the starting arguments.

For Java:

   firefoxBinary.addCommandLineOptions("--headless");
1

To enable headless Firefox using selenium-webdriver version 4.0.0-alpha.1 and node 8.x:

const { Builder } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
const options = new firefox.Options();
options.headless();
const driver = new Builder().forBrowser('firefox')
    .setFirefoxOptions(options).build();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.