赞
踩
- import uiautomation as u
- import time
- """
- uiautomation 自动化包 打开微信 并获取最后一条消息
- """
- def openwx1():
- """
- """
- #显示桌面
- #u.ShowDesktop()
- #查找微信窗口
- wdw = u.WindowControl(Name="微信",searchDepath=2)
- if wdw.Exists(5):
- #切换到窗口
- wdw.SwitchToThisWindow()
- #找到聊天界面
- wx = wdw.ButtonControl(Name="聊天").Click()
- l = wdw.ListControl(Name="会话",searchDepath=2)
- #l.Click(simulateMove=False)
- sessions = l.GetChildren()
- #第一条会话
- sessions[0].Click()
- #消息
- msgs = wdw.ListControl(Name="消息",searchDepath=2).GetChildren()
- #最后一条消息内容
- print("msgs",msgs[-1].Name)
- #输入回复消息内容
- wdw.SendKeys("消息内容",waitTime=0)
- #点击发送
- wdw.ButtonControl(Name="发送(S)",searchDepath=2).Click()
- # i = 0
- # #循环检查是否有新消息
- # while i < 100:
- # #列表里消息
- # msgs = l.GetChildren()
- # for x in msgs:
- # #未读消息
- # print(i,x.Name)
- # if x.Name.endswith("条新消息"):
- # pass
- # time.sleep(1)
- # i += 1
-
- else:
- print("not open wx")
-
- def openwx2():
- """
- 从任务栏中点击打开微信
- """
- t = u.PaneControl(Name='任务栏')
- t.Click()
- wx = t.ButtonControl(Name="微信",searchDepath=1)
- if wx.Exists(1):
- wx.Click()
- w = u.WindowControl(Name="微信",searchDepath=2)
- w.ButtonControl(Name="聊天",searchDepath=2).Click()
- l = w.ListControl(Name="会话",searchDepath=2)
- else:
- print("wx not Exists")
-
- openwx1()
- #openwx2()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。