Try the below steps. It works for me
· Open a command prompt and navigate to the folder containing geckodriver.exe.
· Then start the geckodriver.exe from a command prompt.
· Open another command prompt and type python and press the Return key.
· Copy/paste the following code into your python session.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver import Firefox
options = Options()
options.add_argument("--headless")
# Don't put the path to geckodriver in the following. But the firefox executable
# must be in the path. If not, include the path to firefox, not geckodriver below.
driver = Firefox(firefox_options=options)
print("Firefox Headless Browser Invoked")
driver.get('http://google.com/')
# Print the first 300 characters on the page.
print(driver.page_source[:300])
driver.quit()