Skip to content
Advertisement

How to get a full-page screenshot in Python using Selenium and Screenshot

I’m trying to get a full-length screenshot and haven’t been able to make it work. Here’s the code I’m using:

from Screenshot import Screenshot
from selenium import webdriver
import time

ob = Screenshot.Screenshot()
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
url = "https://stackoverflow.com/questions/73298355/how-to-remove-duplicate-values-in-one-column-but-keep-the-rows-pandas"
driver.get(url)
img_url = ob.full_Screenshot(driver, save_path=r'.', image_name='example.png')
print(img_url)
driver.quit()

But this gives us a clipped screenshot:

enter image description here

So as you can see that’s just what the driver window is showing, not a full-length screenshot. How can I tweak this code to get what I’m looking for?

Advertisement

Answer

To get a full-page screenshot using Selenium-Python clients you can use the GeckoDriver and based save_full_page_screenshot() method as follows:

  • Code:

    driver = webdriver.Firefox(service=s, options=options)
    driver.get('https://stackoverflow.com/questions/73298355/how-to-remove-duplicate-values-in-one-column-but-keep-the-rows-pandas')
    driver.save_full_page_screenshot('fullpage_gecko_firefox.png')
    driver.quit()
    
  • Screenshot:

fullpage_gecko_firefox


tl; dr

[py] Adding full page screenshot feature for Firefox

Advertisement