Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k 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 (62.9k 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!

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!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...