diff --git a/Commons/ui_auto/basic_page.py b/Commons/ui_auto/basic_page.py index e0ab62a..95a46c2 100644 --- a/Commons/ui_auto/basic_page.py +++ b/Commons/ui_auto/basic_page.py @@ -93,6 +93,7 @@ class BasicPage: """ self.driver.execute_script("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", element) + def __wait_element_visible(self, model: str, locator: tuple) -> None: """ 等待元素可见 @@ -291,6 +292,33 @@ class BasicPage: self.set_img_error() raise e + def click_elements(self, locator: tuple, mode: str = "click", alignment: bool = False, move_elemnet: bool = False, + is_double_click: bool = False) -> None: + """ + 点击一组元素 + :param locator: 元素的定位表达式 例:(By.xx,'定位表达式') + :param mode: visible(元素可见),notvisible(元素消失不可见), exist(元素存在),click(元素可点击) + :param alignment: 默认对其方式是元素和当前页面的底部对齐,可以传 alignment=''表示和顶部对齐 + :param move_elemnet: 这里是布尔值 传入True 表示需要让元素滚动到页面可见区域 False 表示不用 + :param is_double_click: False单击元素,传入True 双击元素 + :return: 无返回值 + """ + model = self.get_current_url_path() + elements = self.find_elements(locator=locator, mode=mode) + if move_elemnet is True: + self.__move_element_visible(model=model, locator=locator, element=elements[0], alignment=alignment) + try: + Log.debug(f"点击:{model}页面,属性为{locator}的元素") + for element in elements: + if is_double_click: + ActionChains(self.driver).double_click(element).perform() + else: + element.click() + except Exception as e: + Log.error(f"页面{model}的元素: {locator} 点击失败") + self.set_img_error() + raise e + def random_click_element(self, locator: tuple, num: int, mode: str = "click", alignment: bool = False, move_elemnet: bool = False) -> str: """