How to make firefox headless programatically in Selenium with python?

0
0

i am running this code with python, selenium, and firefox but still get ‘head’ version of firefox:

binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe', log_file=sys.stdout)
binary
.add_command_line_options('-headless')
self
.driver = webdriver.Firefox(firefox_binary=binary)

I also tried some variations of binary:

binary = FirefoxBinary('C:\\Program Files\\Nightly\\firefox.exe', log_file=sys.stdout)
binary
.add_command_line_options("--headless")

any idea what could be going wrong?
Thanks!

  • You must to post comments
0
0

The Release Notes of Selenium v3.6.0 clearly mentions Add options to start Firefox and Chrome in headless modes. So we need to use the Options Class as follows to invoke the headless argument:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options
= Options()
options
.add_argument("--headless")
driver
= webdriver.Firefox(firefox_options=options, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
print("Firefox Headless Browser Invoked")
driver
.get('http://google.com/')
driver
.quit()
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website