0

I want to take a screenshot with python/selenium with fixed size.

In a strange way, the image is always -76 pixels in height.

As a workaround I just add 76 pixels to the window_size. Can this be done in another way? It's important that the images is exactly 1080 x 1920 and I'm afraid that this solution is only temporary.

My code

#!/usr/bin/env python3

from pyvirtualdisplay import Display
import sys
import os
from selenium import webdriver

# Portrait mode 1080 width, 1920 height
display = Display(visible=0, size=(1080, 1920))
display.start()

browser = webdriver.Firefox()

# Needs to be 76 pixels more than desired???
browser.set_window_size(1080,1996)
browser.set_window_position(0, 0)

browser.get('https://google.com')

# Actually prints out 1080 x 1966
print(browser.get_window_size())

# Saves the file in 1080 x 1920
browser.save_screenshot('screenshot.png');

Solution

Thanks to Andersson. The problem is the viewport size. Solution found here: How to set browser viewport size

user1427930
  • 109
  • 2
  • 9
  • 1
    Possible duplicate of [How to set browser viewport size](https://stackoverflow.com/questions/37181403/how-to-set-browser-viewport-size) – Andersson Jan 05 '18 at 16:54
  • Thanks @Andersson. I wouldn't consider it as a duplicate, but similar. The answer did the trick though so I'm happy :) – user1427930 Jan 05 '18 at 17:04

0 Answers0