diff --git a/method/base_method.py b/method/base_method.py index 313852ca248fdc20e87a8671880ef6cdbb6a8943..b899d3b9f538a858b01e0a19be41ea40856e2c0f 100644 --- a/method/base_method.py +++ b/method/base_method.py @@ -43,21 +43,7 @@ class BaseMethod: def base_method_click_by_img(self, img_name): """通过图像识别点击""" - all_pngs = set() - img_name_tmp = img_name.split('.')[0] - - for tmp in os.listdir(config.IMAGE_RES): - if re.search(f'^{img_name_tmp}\d*.png', tmp): - all_pngs.add(tmp) - for img_tmp in all_pngs: - try: - pylinuxauto.find_element_by_image(f"{config.IMAGE_RES}/{img_tmp}").click() - break - except pylinuxauto.exceptions.TemplateElementNotFound: - pass - else: - raise pylinuxauto.exceptions.TemplateElementNotFound(img_name) - + pylinuxauto.find_element_by_image(f"{config.IMAGE_RES}/{img_name}").click() def base_method_double_click_by_img(self, img_name): """通过图像识别双击""" diff --git a/method/dde_method.py b/method/dde_method.py index 5dc82549780485bf24818b9ebf80a18ad03891a9..2d7495feded377fce0ae81a0c997c94f983a618f 100644 --- a/method/dde_method.py +++ b/method/dde_method.py @@ -47,7 +47,17 @@ class DdeMethod( def dde_method_close_window(self): """关闭窗口""" - self.base_method_click_by_img("close_window_btn.png") + def get_euler_version(): + """获取 openEuler 版本信息,默认图片失败时使用版本图片定位""" + with open("/etc/openEuler-release") as f: + data = f.readline() + return "".join(data.split(" ")[2:]).strip() + + try: + self.base_method_click_by_img("close_window_btn.png") + except pylinuxauto.exceptions.TemplateElementNotFound: + euler_version = get_euler_version() + self.base_method_click_by_img(f"close_window_btn_{euler_version}.png") def dde_method_delete_keyboard_layout_in_control_center(self): """在控制中心的键盘布局视图删除除选中之外的布局""" diff --git a/method/image_res/close_window_btn2.png b/method/image_res/close_window_btn_23.09.png similarity index 100% rename from method/image_res/close_window_btn2.png rename to method/image_res/close_window_btn_23.09.png