OS: Windows, macOS, Linux
Selenium Version: 3.5.0
Browser: Firefox
Browser Version: 56
Once Firefox supports headless mode on all three platforms (starting with Firefox 56, currently in beta and due to be released next month), the selenium-webdriver package should support configuring Firefox to run headlessly the same way it supports Chrome running headlessly, via a headless() method on the Firefox driver's _Options_ class, so that you can drive Firefox headlessly via:
const { Builder } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
const driver = new Builder()
.forBrowser('firefox')
.setFirefoxOptions(new firefox.Options().headless())
.build();
(It would additionally be useful to be able to set the headless window's size via the equivalent of Chrome's windowSize({width, height}) method.)
This option should be added to all language binding.
Implemented in Java binding by 38a5130ca52be0fa69632ee969ffa6846cfd25e7
As far as I can tell, this is already possible with the Ruby bindings:
~~~ruby
options = Selenium::WebDriver::Firefox::Options.new(
args: ['-headless']
)
Selenium::WebDriver.for :firefox, options: options
~~~
@franzliedke yes it is most likely possible with all bindings, but this is asking for a shortcut without having to specify it in args
Right, note that Chrome already supports this configuration in selenium-webdriver:
And selenium-webdriver also provides an example script using it:
Although strangely the docs don't mention it:
This issue is about doing the same for Firefox. It may be merely syntactic sugar, but it's useful nonetheless.
Thanks for clarification. I sent a PR for the Ruby bindings: #4762.
Added to python in 1d490b4
dotnet please! đ
Iâm hoghly disinclined to implement this for .NET. It was a mistake for other bindings to implement it as well. The ability to add commmsnd line arguments to both Firefox and Chrome is there already; use the AddArgument method in the respective Options classes. Why special case âheadlessâ? It wouldnât make the userâs code any more or less verbose, plus it obscures the browser configuration (i.e., âhow is a browser made to run âheadlessâ?â). Iâm not sure I fully understand the use case.
@jimevans I see this as a case of the API can expose a common config option without requiring users to be intimately familiar with a browser's command line arguments. It's not unlike having strongly typed APIs for capabilities vs. expecting users to know all of the various key/value pairs.
I understand the analogy, @jleyba, I just donât think I agree with it. Capabilities are a much smaller finite set of settings. To me, itâs really hard to justify adding an API for a single command line argument while ignoring the potentially dozens of others.
Closing as it was resolved after reading the comments.
Most helpful comment
As far as I can tell, this is already possible with the Ruby bindings:
~~~ruby
options = Selenium::WebDriver::Firefox::Options.new(
args: ['-headless']
)
Selenium::WebDriver.for :firefox, options: options
~~~