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)

```
Here is a function that does just that, The sizes must be casted to integers before being passed to the crop function :

```
from PIL import Image
from StringIO import StringIO
def capture_element(element,driver):
  location = element.location
  size = element.size
  img = driver.get_screenshot_as_png()
  img = Image.open(StringIO(img))
  left = location['x']
  top = location['y']
  right = location['x'] + size['width']
  bottom = location['y'] + size['height']
  img = img.crop((int(left), int(top), int(right), int(bottom)))
  img.save('screenshot.png')

```