I'm using the below code to take a screenshot and crop just the element I want. However, as Chrome only takes a screenshot of the viewport the top number is too large as it is counting from the top of the page. Is there a way to get the location relative to the viewport?
element = browser.find_element_by_xpath(locator)
browser.save_screenshot('screenshot.png')
location = element.location
size = element.size
im = Image.open('screenshot.png')
left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height']
im = im.crop((int(left), int(top), int(right), int(bottom)))
im.save('screenshot2.png')