為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

How to make FireFox headless programmatically in Selenium with python?

  • 2 回覆
  • 1 有這個問題
  • 1 次檢視
  • 最近回覆由 cor-el

more options

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")

由 Rohit bhat 於 修改

所有回覆 (2)

more options

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)

由 silvanocerza 於 修改

more options

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: