Headless Firefox in Selenium C#
Headless mode in Firefox is supported from version 56 on Windows and Mac OS. Ensure that you have the correct version installed.
https://developer.mozilla.org/en-US/Firefox/Headless_mode#Browser_support
With Firefox v56.0.1, Selenium.WebDriver v3.6.0 and geckodriver v0.19.0 (x64) this works correctly for me.
Regarding the error:
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Ensure you're using the correct version of geckodriver
. I suspect you're using the x32
build on an x64
machine, get the x64
build.
https://github.com/mozilla/geckodriver/releases
Comments
-
Biswajit Chopdar almost 2 years
I want to run firefox headless.
Not hide the browser window or open it in a virtual desktop, Firefox supports headless mode by using "-headless" flag.
Problem is I know how to do it in chrome but not in Firefox.
My code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; namespace MyApp { public partial class Form1: Form { public Form1() { InitializeComponent(); } private void StartBtn_Click(object sender, EventArgs e) { IWebDriver driver; FirefoxOptions options = new FirefoxOptions(); options.AddArguments("--headless"); driver = new FirefoxDriver(options); } } }
My WinForm application only has a button with name StartBtn. On clicking of the button Firefox should run headless, but it opens in a normal window.
Update I updated firefox to 56.0.1
Now I get a different error:
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Additional information: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
-
Biswajit Chopdar over 6 yearsit shows an exception when I use
--headless
. All arguments must start with two dashes ('--'); argument '-headless' does not. -
Biswajit Chopdar over 6 yearsI updated firefox to the latest version, I now get a different error. Please check my updated question.
-
Equalsk over 6 years@Raven Which version of
geckodriver
are you using? I think you're probably using 32-bit on a 64-bit system. Try the x64 version: github.com/mozilla/geckodriver/releases -
Biswajit Chopdar over 6 yearsReplacing the 32bit geckodriver with the 64bit worked. Big Thank you!