1

I need to capture a screenshot of a page with a mobile viewport width. The window height needs to be ~18000px to include all the content on the page without scrolling.

Every time I call set_window_size(), get_window_size() reports a smaller height and my screenshots are cut off:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

fox_options = Options()
fox_options.headless = True

driver = webdriver.Firefox(options=fox_options)
driver.get("https://foo.bar")

driver.set_window_size(450, 18355)
driver.get_window_size()
>> {'width': 450, 'height': 16384}

Smaller heights are set correctly. There doesn't seem to be a hard height limit, I can create even larger windows when opening larger pages with more content, but the window is always ~2000px smaller than it needs to be.

I tried:

  • Adding 2000 to the height passed to set_window_size(), no effect.
  • set_window_position(0, 0) before set_window_size(), no effect.
  • Older versions of Firefox + geckodriver (77.0.1, 0.26.0): this DOES WORK, but not an option.

Versions: Selenium 4.1.0, geckodriver 0.30.0, Firefox 96.0.

Is this a bug in newer versions? Does anyone have a workaround?

Alternative ways of capturing the entire page would be good too, but the methods in this answer don't work for various reasons.

kontextify
  • 478
  • 5
  • 16

0 Answers0