python 遍历微信各个按钮
import time,sys import psutil from pywinauto.application import Application from time import sleep from pywinauto import mouse from pywinauto.keyboard import send_keys from pywinauto import keyboard # 常用方式一:连接已有微信进程(进程号在 任务管理器-详细信息 可以查看) def GetWeChatPID(name): # 获得全部进程的ID # pids=psutil.pids() pids = psutil.process_iter() # 遍历全部进程ID for pid in pids: if(pid.name()==name): # 输出进程ID return pid.pid # 没有找到则输出0 return print('请打开微信') pid = GetWeChatPID('WeChat.exe') app = Application(backend='uia').connect(process=pid) win_main_Dialog = app.window(class_name='WeChatMainWndForPC') # 判断是否为dialog,一个微信是一个dialog,就是窗口 print(win_main_Dialog.is_dialog) # 给控件画个红色框便于看出是哪个 #win_main_Dialog.draw_outline(colour = 'red') # 打印当前窗口的所有controller(控件和属性) #win_main_Dialog. print_control_identifiers(depth=None, filename=None) #aa=win_main_Dialog.control_identifiers(depth=None, filename=None) # 源码内部函数名链式赋值了,都能用,一样的 # print_ctrl_ids = dump_tree = print_control_identifiers # 拿到微信主窗口 win_main_Dialog = app.window(class_name='WeChatMainWndForPC') #win_main_Dialog1 = app.window(found_index=0,class_name='WeChatMainWndForPC').type_keys('~') win = app[u'微信'] # 将窗口最大化 #win.maximize() for ii in range(100): try: btn_return = win_main_Dialog.child_window(control_type='Button',found_index=ii).parent().descendants(control_type='Button') except: break for i in btn_return: print(ii,i)