How to make sure the dimensions of screenshot taken in headless mode Firefox driver are always same?
Just add an option right after headless to set the window size:
firefox_options.add_argument("--window-size=1920x1080")
The driver.fullscreen_window()
line isn't necessary for headless mode.
If I'm not mistaken when you use Options()
you should go with it all the way!
So in your case, I would do this:
firefox_options = Options()firefox_options.add_argument("--headless")firefox_options.add_argument('--start-maximized')driver = webdriver.Firefox(firefox_options=firefox_options)driver.get('file:///'+q.html.path)shot = driver.get_screenshot_as_png()driver.close()
Hope this helps!