Why do I get small screenshots with pyvirtualdisplay in selenium tests?

1.2k Views Asked by At

I am using complex selenium tests and pyvirtualdisplay in order to take screenshots during the selenium testing. However, I am using the following code to create a Display:

 self.display = Display(visible=0, size=(1366, 768))
 self.display.start()

and something like this code

self.driver.save_screenshot(savename)

to create a screenshot (where self.driver is a selenium-webdriver). However, the screenshots I get are much smaller that defined, like 911x197 pixels. Do I have to make some special configurations to get a better screenshot? So far I only can see small parts of the headless browser I am using for testing...

1

There are 1 best solutions below

0
On

Do you start your browser with "--start-maximized" option?

from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def browser():
    opts = Options()
    opts.add_argument('--start-maximized')
    d = Display(visible=0, size=(1920, 1024))
    d.start()
    b = webdriver.Chrome(chrome_options=opts)