pythonseleniumselenium-webdrivergeckodriverfirefox-headless

Python Selenium:firefox headless option not working with Firefox 52.8.0 (32-bit)


I want to run firefox in headless mode on server but both options.add_argument("--headless") and options.set_headless(headless=True) are not working.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
print("Executing script")
options = Options()
#options.add_argument("--headless")
options.set_headless(headless=True)
try:
    driver = webdriver.Firefox(firefox_options=options, 
    executable_path="/path-to-driver/geckodriver.exe");
    driver.get("https://www.google.com")
    print(driver.page_source)
finally:
driver.quit()
print ("Script executed successfully")

I am using Python 3.6.5, Selenium 3.12.0 and firefox 52.8.0 (32-bit).


Solution

  • I don't see any such issue in your code trails. However it seems there is a version mismatch within the binaries you are using as follows:

    The milestone for Mozilla Headless Mode was Mozilla v55.0a1


    Solution

    Upgrading your Mozilla Browser Client to Mozilla v55.0a1 or above will address your issue.