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: 
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')

```
Just simple as that:

```
element = driver.find_element_by_class_name('myclass')
element.screenshot('screenshot.png')

```