Taking a full page screenshot helps you capture the entire webpage, not just the visible part. This is useful to check the full layout and content in one image.
Full page screenshot in Selenium Python
driver.get_screenshot_as_file('filename.png')This command saves the visible part of the page as an image file.
To capture the full page, you may need to use browser-specific options or scroll and stitch images.
driver.get_screenshot_as_file('visible_part.png')driver.execute_script('window.scrollTo(0, document.body.scrollHeight)') driver.get_screenshot_as_file('scrolled_page.png')
from selenium import webdriver from selenium.webdriver.chrome.options import Options import base64 options = Options() options.add_argument('--headless=new') options.add_argument('--hide-scrollbars') options.add_argument('--window-size=1920,1080') driver = webdriver.Chrome(options=options) screenshot = driver.execute_cdp_cmd('Page.captureScreenshot', {'captureBeyondViewport': True}) with open('full_page.png', 'wb') as file: file.write(base64.b64decode(screenshot['data']))
This script opens example.com in Chrome headless mode, waits for the page to load, uses Chrome DevTools Protocol to save a full page screenshot as 'full_page_example.png', and prints confirmation.
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options import time import base64 options = Options() options.add_argument('--headless=new') # Use new headless mode for full page screenshot support options.add_argument('--window-size=1920,1080') service = Service() driver = webdriver.Chrome(service=service, options=options) try: driver.get('https://example.com') time.sleep(2) # Wait for page to load screenshot = driver.execute_cdp_cmd('Page.captureScreenshot', {'captureBeyondViewport': True}) with open('full_page_example.png', 'wb') as f: f.write(base64.b64decode(screenshot['data'])) print('Full page screenshot saved successfully.') finally: driver.quit()
Full page screenshot can be captured using Chrome DevTools Protocol (CDP) driver.execute_cdp_cmd('Page.captureScreenshot', {'captureBeyondViewport': True}) (Chrome 59+). Requires import base64.
If your browser does not support full page screenshots natively, you may need to scroll and stitch images manually.
Always wait for the page to fully load before taking a screenshot to avoid incomplete captures.
Full page screenshots capture the entire webpage, not just what you see on screen.
Use Chrome DevTools Protocol like driver.execute_cdp_cmd('Page.captureScreenshot', {'captureBeyondViewport': True}) for easy full page capture.
Waiting for page load and using headless mode helps get clean, complete screenshots.