X
Tap here to go to the mobile version of the site.

Support Forum

How to make FireFox headless programmatically in Selenium with python?

Posted

I am running this code with Python (http://bit.ly/38YA0O1), 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")
I am running this code with Python (http://bit.ly/38YA0O1), 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")

Modified by Rohit bhat

Quote

Additional System Details

Application

  • User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36

More Information

silvanocerza 0 solutions 4 answers

Like this:

   options = Options()
   options.headless = True
   driver = webdriver.Firefox(options=options, executable_path='C:\\Program Files(x86)\\Mozilla Firefox\\firefox.exe', log_file=sys.stdout)

or by setting the env var MOZ_HEADLESS:

   import os
   os.environ["MOZ_HEADLESS"] = "1"
   driver = webdriver.Firefox(executable_path='C:\\Program Files (x86)\\MozillaFirefox\\firefox.exe', log_file=sys.stdout)
Like this: options = Options() options.headless = True driver = webdriver.Firefox(options=options, executable_path='C:\\Program Files(x86)\\Mozilla Firefox\\firefox.exe', log_file=sys.stdout) or by setting the env var MOZ_HEADLESS: import os os.environ["MOZ_HEADLESS"] = "1" driver = webdriver.Firefox(executable_path='C:\\Program Files (x86)\\MozillaFirefox\\firefox.exe', log_file=sys.stdout)

Modified by silvanocerza

Was this helpful to you?
Quote
cor-el
  • Top 10 Contributor
  • Moderator
17876 solutions 161748 answers

I don't think that headless mode works with a profile used for normal mode.

Are you using a special profile for running Firefox in headless mode ?

You need to use the Profile Manager to create the new profile folder, but not launch Firefox (i.e. click Exit). You need to specify this profile via -P "profile-name" command line switch.

See:

I don't think that headless mode works with a profile used for normal mode. Are you using a special profile for running Firefox in headless mode ? You need to use the Profile Manager to create the new profile folder, but not launch Firefox (i.e. click Exit). You need to specify this profile via -P "profile-name" command line switch. See: *https://developer.mozilla.org/en/Mozilla/Firefox/Headless_mode
Was this helpful to you?
Quote
Ask a question

You must log in to your account to reply to posts. Please start a new question, if you do not have an account yet.