How to make Firefox headless programmatically in Selenium with Python?

Sometimes, we want to make Firefox headless programmatically in Selenium with Python.

In this article, we’ll look at how to make Firefox headless programmatically in Selenium with Python.

How to make Firefox headless programmatically in Selenium with Python?

To make Firefox headless programmatically in Selenium with Python, we can set the headless property to True.

For instance, we write

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:UtilityBrowserDriversgeckodriver.exe')
driver.get("http://example.com/")
driver.quit()

to create an Options object.

And we set the headless property of it to True.

Then we create a webdriver.Firefox object with the options argument set to options to make Firefox headless.

Then we call get to open a web page at the given URL.

Conclusion

To make Firefox headless programmatically in Selenium with Python, we can set the headless property to True.