Question: I have searched a lot for this but couldn't find a solution. Here's [a similar question](https://stackoverflow.com/questions/10848900/how-to-take-partial-screenshot-frame-with-selenium-webdriver) with a possible solution in java.

Is there a similar solution in Python?

Answer: 
Worked for me in python3.5

```
from selenium import webdriver

fox = webdriver.Firefox()
fox.get('http://stackoverflow.com/')
image = fox.find_element_by_id('hlogo').screenshot_as_png

```

p.s.

To save to file

```
image=driver.find_element_by_id('hlogo').screenshot(output_file_path)

```
I converted @randomphobia's answer into a function. I also used @bummis' suggestion of using `location_once_scrolled_into_view` instead of `location` in order to generalize no matter the size of the page.

```py
from selenium import webdriver
from PIL import Image
from io import BytesIO

def take_screenshot(element, driver, filename='screenshot.png'):
  location = element.location_once_scrolled_into_view
  size = element.size
  png = driver.get_screenshot_as_png() # saves screenshot of entire page

  im = Image.open(BytesIO(png)) # uses PIL library to open image in memory

  left = location['x']
  top = location['y']
  right = location['x'] + size['width']
  bottom = location['y'] + size['height']

  im = im.crop((left, top, right, bottom)) # defines crop points
  im.save(filename) # saves new cropped image

```

Here's a gist: <https://gist.github.com/WittmannF/b714d3ceb7b6a5cd50002f11fb5a4929>