Reputation: 91
I want to take screenshot of a local html page in full-screen. But the following code produces different dimensional files(screenshots) for different html files. I find it strange as I am doing it full-screen, It should not happen. Please help.
firefox_options = Options()
firefox_options.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=firefox_options)
driver.get('file:///'+q.html.path)
driver.fullscreen_window()
shot = driver.get_screenshot_as_png()
driver.close()
Upvotes: 2
Views: 360
Reputation: 1308
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.
Upvotes: 1
Reputation: 5204
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!
Upvotes: 0