Selenium Screenshot Works Slow (Python)
You could save some time by cropping the screenshot in memory without saving it first to a file:
import StringIOfrom selenium import webdriverfrom PIL import Imagedriver = webdriver.Firefox()driver.get('http://stackoverflow.com')element = driver.find_element_by_id('hlogo')crop_points = driver.execute_script(""" var r = arguments[0].getBoundingClientRect(); return [r.left, r.top, r.left + r.width, r.top + r.height]; """, element)with Image.open(StringIO.StringIO(driver.get_screenshot_as_png())) as img : with img.crop(crop_points) as imgsub : imgsub.save(logo.png', 'PNG')