Search code examples
pythonselenium-webdriverselenium-chromedriver

Full page screenshot with Selenium Chrome driver in Python


AI insists that for Selenium 4 or later to take the full page screenshot with webdriver.Chrome(), you can use the 'full' argument in driver.get_screenshot_as_file("screenshot.png", full=True). However, I get error message

TypeError: WebDriver.get_screenshot_as_file() got an unexpected keyword argument 'full'

Please, help.


Solution

  • The error message does a pretty good job here: WebDriver.get_screenshot_as_file() does not have a keyword argument called 'full'.

    Here is a method I have used in the past:

    def save_screenshot():
        original_size = driver.get_window_size()
        required_width = driver.execute_script('return document.body.parentNode.scrollWidth')
        required_height = driver.execute_script('return document.body.parentNode.scrollHeight')
        driver.set_window_size(required_width, required_height)
        driver.find_element_by_tag_name('body').screenshot(path)
        driver.set_window_size(original_size['width'], original_size['height'])