class TestDemo:
def __init__(self, driver):
self.driver = driver
def find_image(self, target):
# 定义截图路径
screen_path = os.path.join(screen_image, "screen.png")
# 截图
self.driver.get_screenshot_as_file(screen_path)
source = cv.imread(screen_path)
template = cv.imread(target)
result = cv.matchTemplate(source, template, cv.TM_CCOEFF_NORMED)
imin, imax, min_loc, max_loc = cv.minMaxLoc(result)
if imax > 0.95:
pos_x = max_loc[0] + int(template.shape[1] / 2)
pos_y = max_loc[1] + int(template.shape[0] / 2)
return [True, (pos_x, pos_y)]
else:
return False