Despite using Selenium and FirefoxBinary with command-line arguments, you may still encounter Firefox running in its "head" version. To resolve this issue and successfully invoke Firefox headless, follow these steps:
In your Python script, you can set the headless property in the Options() class as shown below:
from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options() options.headless = True driver = webdriver.Firefox(options=options, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
Alternatively, you can set the environment variable MOZ_HEADLESS to any non-zero value to run Firefox headless:
$ MOZ_HEADLESS=1 python manage.py test
To enable/disable headless mode on the fly without modifying code, you can export the variable as follows:
$ export MOZ_HEADLESS=1 $ python manage.py test … $ unset MOZ_HEADLESS
How to configure ChromeDriver to initiate Chrome browser in headless mode through Selenium?
The above is the detailed content of How to Run Firefox in Headless Mode with Selenium and Python?. For more information, please follow other related articles on the PHP Chinese website!