def screenshotself file_name driver=None point= 截指定云手机图pointPoin param point 截取范围 x1y1x2y2 param driver 浏览器 return el = driverfind_elementby=ByCSS_S
def screenshot(self, file_name, driver=None, point=[]): """ 截指定云手机图point:Poin, :param point: 截取范围 [x1,y1,x2,y2] :param driver: 浏览器 :return: """ el = driver.find_element(by=By.CSS_SELECTOR, value="#remoteVideo")
# 截取截图
full_screenshot = el.screenshot_as_png
# 使用PIL加载全屏截图
image = Image.open(BytesIO(full_screenshot))
# 定义要截取的矩形区域(左上角坐标(x1,y1),右下角坐标(x2,y2))
if point == []:
x1 = 0
y1 = 0
x2 = el.size["width"]
y2 = el.size["height"]
else:
x1 = point[0]
y1 = point[1]
x2 = point[2]
y2 = point[3]
# 从全屏截图中截取矩形区域
region = image.crop((x1, y1, x2, y2))
# 转换为24位深度
region = region.convert("RGB")
# 将截取的区域保存到文件
region.save(file_name, "PNG", bits=24)
return regio
原文地址: https://www.cveoy.top/t/topic/iUwz 著作权归作者所有。请勿转载和采集!