Once you’ve got Selenium working, using Headless Firefox is a breeze. For example, let’s see if we can get to Intellipaat’s official website page.
Since Headless Firefox has no visible browser, we’ll take a screenshot to confirm what the browser is doing.
from selenium import webdriver
geckodriver = 'C:\\Users\\ThisPC\\Downloads\\geckodriver.exe'
options = webdriver.FirefoxOptions()
options.add_argument('-headless')
browser = webdriver.Firefox(executable_path=geckodriver, firefox_options=options)
browser.get('https://www.intellipaat.com')
browser.save_screenshot('C:\\Users\\ThisPC\\Downloads\\headless_firefox_test.png')
browser.quit()
If the script finishes and your screenshot shows Intellipaat’s home page, you’re all set!
If something’s not working, make sure Selenium, Firefox, and gecko drivers are all up-to-date and try again.
I hope it helps you run your code!
If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium certification!