I am trying to save particular element from html to be saved as image file using OpenCV and selenium. But unable to save the file.
from selenium import webdriver
import cv2
import numpy as np
browser = webdriver.Firefox()
browser.get(<URl with image>)
# Element to be saved
element = browser.find_element_by_id(<id of element>)
png = browser.get_screenshot_as_png()
location = element.location
size = element.size
nparr = np.frombuffer(png, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height']
im = img[left:right, top:bottom]
cv2.imwrite('filename.png',im)
Currently there is no image data in 'filename.png'
by running this script.