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.
Practice
Solution
Step 1: Understand what a full page screenshot means
A full page screenshot captures the entire webpage, not just the visible part on the screen.Step 2: Compare options with this definition
Only It captures the entire webpage, including parts not visible on screen correctly states this advantage. Options B, C, and D describe other unrelated behaviors.Final Answer:
It captures the entire webpage, including parts not visible on screen -> Option CQuick Check:
Full page screenshot = entire page capture [OK]
- Confusing full page with visible viewport only
- Thinking it speeds up tests automatically
- Assuming it scrolls the page during capture
Solution
Step 1: Identify the correct method for full page screenshot in Firefox
Firefox does not have a built-in method namedsave_full_page_screenshot. The standard method to save a screenshot isget_screenshot_as_file, which captures the visible viewport.Step 2: Check other options for correctness
driver.save_full_page_screenshot('file.png') is invalid assave_full_page_screenshotis not a standard Selenium method. driver.save_screenshot('file.png') saves visible viewport screenshot. driver.take_full_screenshot('file.png') is not a valid method.Final Answer:
driver.get_screenshot_as_file('file.png') -> Option AQuick Check:
Standard screenshot method = get_screenshot_as_file [OK]
- Using non-existent save_full_page_screenshot method
- Confusing save_screenshot with full page capture
- Trying invalid methods like take_full_screenshot
driver.get('https://example.com')
driver.save_full_page_screenshot('page.png')
print('Screenshot saved')Solution
Step 1: Analyze the method usage
The methodsave_full_page_screenshotis not a valid Selenium WebDriver method and will cause a SyntaxError or AttributeError.Step 2: Check the print statement
The print statement will not execute because the previous line causes an error.Final Answer:
SyntaxError due to incorrect method name -> Option DQuick Check:
Invalid method call causes error [OK]
- Assuming method is supported causing success
- Confusing full page with visible screenshot
- Thinking method name is correct syntax
driver.get('https://example.com')
driver.save_screenshot('screen.png')
What is the likely cause?Solution
Step 1: Understand why screenshot is blank
If the page is not fully loaded, the screenshot may capture a blank or incomplete page.Step 2: Evaluate other options
save_screenshot does save files. Method get_full_page_screenshot_as_file is unrelated to blank screenshot issue. Invalid file path would cause an error, not a blank file.Final Answer:
Page did not fully load before screenshot -> Option AQuick Check:
Wait for page load before screenshot [OK]
- Assuming save_screenshot never saves files
- Confusing full page screenshot with blank image issue
- Ignoring page load timing problems
Solution
Step 1: Understand headless mode limitations
Headless Firefox does not support a built-in full page screenshot method.Step 2: Use manual scrolling and multiple viewport screenshots
To capture the full page, scroll manually and stitch multiple viewport screenshots.Final Answer:
Scroll manually and take multiple viewport screenshots -> Option BQuick Check:
Manual scroll + multiple screenshots = full page capture [OK]
- Assuming save_full_page_screenshot exists in headless mode
- Taking screenshot immediately without waiting
- Hiding elements unnecessarily before capture
Ready to prove it?
Pass the test and this pattern moves unknown
