一、通过xpath获取对应区域的图片或者文字,再基于python开源库进行图片或文本对比。
"actions": [
{
"action": "click",
"xpath": "//a[@class='nav-menu-li-link' and @href='/brand/realTime/realSummary.html']"
},
{
"action": "move",
"xpath": "//div[@id='graceNavBox']"
},
{
"action": "click",
"xpath": "//a[@class='grace-menu-title-wrapper ' and @href='/brand/realTime/realSummary.html']"
}
二、图像进行对比
playwright(官网- https://playwright.bootcss.com/)
图像对比实现用到python库:imutils,skimage.metrics,cv2,numpy
利用图片相似度进行处理
(score, diff) = compare_ssim(gray_a, gray_b, full=True)
读取图片
"""
读取图片(解决路径中含有中文无法读取的问题),一般是直接cv2.imread(filea_path)
:param file_path:图片的路径
:return:
"""
cv_img = cv2.imdecode(np.fromfile(file_path, dtype=np.uint8), -1)
height, width = image_a.shape[:2]
image.shape[:2]与image.shape[:3]
[0:2]是切片的意思,.shape 应当是OpenCV模块中处理图片的,是图片的一个属性,这个属性是个列表 ,然后对这个列表切片操作。
例子:h,w = img.shape[:2] 获取彩色图片的高、宽,并且赋值给h和w;如果是h,w,v = img.shape[:3] 获取彩色图片的高、宽、通道,并赋值给h w v
# 找到不同点的轮廓以致于我们可以在被标识为“不同”的区域周围放置矩形:
thresh = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)