import logging from uiautomator2 import Device def click_search_btn(d: Device): selector = d.xpath('//*[@resource-id="com.tencent.mm:id/h5n"]') if selector.exists: selector.click() else: logging.warning("未找到组件") def input_search_text(d: Device, text: str): clear_btn = d.xpath('//*[@resource-id="com.tencent.mm:id/nhn"]') if clear_btn.exists: clear_btn.click() selector = d.xpath('//*[@resource-id="com.tencent.mm:id/mdd"]') if selector.exists: selector.set_text(text) else: logging.warning("未找到组件") def click_search_result(d: Device): selector = d.xpath('//*[@resource-id="com.tencent.mm:id/kbo"]') selector.wait(timeout=5) elements = selector.all() print(elements) if len(elements) > 0: elements[0].click() else: logging.warning("未找到组件") def input_chat_text(d: Device, text: str): selector = d.xpath('//*[@resource-id="com.tencent.mm:id/bkk"]') selector.wait(timeout=5) if selector.exists: selector.set_text(text) else: logging.warning("未找到组件") selector = d.xpath('//*[@resource-id="com.tencent.mm:id/bql"]') selector.wait(timeout=1) selector.click()