0 votes
1 view
in Devops and Agile by (23.1k points)

I am running this code with python, selenium, and firefox but still get 'head' version of firefox:

binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe', log_file=sys.stdout)

binary.add_command_line_options('-headless')

self.driver = webdriver.Firefox(firefox_binary=binary)

I also tried some variations of binary:

binary = FirefoxBinary('C:\\Program Files\\Nightly\\firefox.exe', log_file=sys.stdout)

        binary.add_command_line_options("--headless")

1 Answer

0 votes
by (58.7k points)

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!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...