I found this reference that works very well with Chrome
https://dev.to/gdledsan/selenium-4-and-chrome-driver-take-full-page-screenthos-2j8d
from selenium import webdriver
import base64
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.tutorialspoint.com/index.htm")
#get window size
page_rect = driver.execute_cdp_cmd('Page.getLayoutMetrics', {})
# parameters needed for full page screenshot
# note we are setting the width and height of the viewport to screenshot, same as the site's content size
screenshot_config = {
'captureBeyondViewport': True,
'fromSurface': True,
'clip': {
'width': page_rect['contentSize']['width'],
'height': page_rect['contentSize']['height'],
'x': 0,
'y': 0,
'scale': 1
}
}
# Dictionary with 1 key: data
base_64_png = driver.execute_cdp_cmd('Page.captureScreenshot', screenshot_config)
# Write img to file
with open("imageToSave.png", "wb") as fh:
fh.write(base64.urlsafe_b64decode(base_64_png['data']))
driver.quit()
As for Firefox, it is much easier to get full page screenshots
driver = webdriver.Firefox()
driver.maximize_window()
driver.get("https://www.tutorialspoint.com/index.htm")
driver.save_full_page_screenshot("imageToSave.png")