UI Automation,也称为UIA,是一个应用程序接口(API),允许一个应用程序访问、识别和操作另一个应用程序的用户界面(UI)元素1。它是微软为了提供和消费用户界面(UI)信息的辅助功能框架 pyautogui是一个跨平台的GUI自动化python模块,用于程序化控制鼠标和键盘 #使用uiautomation库在Python中创建一个WindowControl对象,该对象代表一个窗口控件。这个窗口控件是微信的主窗口。 #searchDepth=1表示在当前窗口的子窗口中搜索 #Name="微信"表示要查找的窗口的名称是“微信”。 #ClassName='WeChatMainWndForPC'表示要查找的窗口的类名是WeChatMainWndForPC self.WeChat = auto.WindowControl(searchDepth=1, Name="微信", ClassName='WeChatMainWndForPC') #EditControl方法被用来获取微信的输入框控件,最新版随着聊天窗口不再变化,输入框的名称不再固定,会随着不同聊天窗口的窗口名而变化,所以代码被更改为self.EditMsg = self.UiaAPI.EditControl(LocalizedControlType='编辑') self.WeChat.EditControl() #ListControl()是WindowControl类的一个方法,用于获取窗口中的列表控件 #self.WeChat.ListControl()这行代码的作用是找到微信主窗口中的会话列表,并将其存储在self.sess self.sess = self.WeChat.ListControl() self.SessionItemList = [] #从所有子控件中筛选出第一个没有类名的子控件。 MainControl1 = [i for i in self.WeChat.GetChildren() if not i.ClassName][0] #MainControl2被赋值为MainControl1的子控件列表中的第一个子控件 MainControl2 = MainControl1.GetChildren()[0]
uiautomation,pyautogui 总结
最新推荐文章于 2024-05-15 02:16:01 发布