How to capture image for an element, not for the whole screen?

Just as the subject.

With self.get_screenshot_as_base64(), we can capture an image for the whole screen. it works with this (‘GET’, ‘/session/$sessionId/screenshot’).

Do we have some approach to capture an image for an element?

In Python, we can use PIL.Image module to handle the image

def capture(self, what):
        begin = what.location
        size = what.size
        start_x = begin['x']
        start_y = begin['y']
        end_x = start_x + size['width']
        end_y = start_y + size['height']
        name = str(start_x)+'_'+str(start_y)+'_'+str(end_x)+'_'+str(end_y)
        box = (start_x, start_y, end_x, end_y)
        self.driver.get_screenshot_as_file(tmp + '/' + 'full_screen.png')
        image = + '/' + 'full_screen.png')
        newimage = image.crop(box) + '/' + name + '.png')
        os.popen('rm %s/full_screen.png' %tmp)

‘what’ is a webelement, ‘tmp’ is a temporary folder.