def update_windows(self): """Update window's handlers.""" win32gui.EnumWindows(self._get_window_info, None) win32gui.EnumChildWindows(self.parent_hwnd, self._get_key_layout_handle, None) win32gui.EnumChildWindows(self.parent_hwnd, self._get_emulator_window_info, None)
def __init_handle(self): # 发送 F4 , 调出界面 self.__enter_hold_panel() """ 获取 持仓界面的 handle 值 每点击几次 句柄都会重建,所以先校验 当前的 handle是否有效 """ if self.__handle: son_of_hold = [] win32gui.EnumChildWindows( self.__parent_trade, lambda handle, param: param.append(handle), son_of_hold) if self.__handle in son_of_hold: li = [] win32gui.EnumChildWindows( self.__handle, lambda handle, param: param.append(handle), li) for l in li: if win32gui.GetWindowText(l) == "资金余额": return # 获取所有 dialog 子句柄 def call_back(handle, hwnd_list): txt = win32gui.GetWindowText(handle) if txt and txt == "资金余额": hwnd_list.append(win32gui.GetParent(handle)) return hwnd_l = [] win32gui.EnumChildWindows(self.__parent_trade, call_back, hwnd_l) self.__handle = hwnd_l[0] # 调用 self.__set_useful_handle()
def findOutputSubWindow(self, handler): handlerList = [handler] def callbackWindow(hwnd, param): if hwnd == 0: return text = win32gui.GetWindowText(hwnd) text = text.decode(u'gb2312') if u'输出区' in text: handlerList.append(hwnd) def callbackEdit(hwnd, param): if hwnd == 0: return clazz = win32gui.GetClassName(hwnd) if u'EDIT' in clazz: handlerList.append(hwnd) hwndChildList = [] win32gui.EnumChildWindows(handlerList[-1], callbackWindow, hwndChildList) win32gui.EnumChildWindows(handlerList[-1], callbackEdit, hwndChildList) if len(handlerList) == 3: return handlerList[-1] return 0
def get_hwnd(self): window_name = 'NanoDrive Innova Tapping' innova_hwnd = win32gui.FindWindow(None, window_name) hwnd = innova_hwnd hwndChildList = [] win32gui.EnumChildWindows(hwnd, lambda hwnd, param: param.append(hwnd), hwndChildList) z_position_hwnd = 0 z_offset_hwnd = 0 for hwnd_child in hwndChildList: name = win32gui.GetWindowText(hwnd_child) if name == 'z_position': z_position_hwnd = hwnd_child elif name == 'z_offset': z_offset_hwnd = hwnd_child hwnd = z_position_hwnd hwndChildList = [] win32gui.EnumChildWindows(hwnd, lambda hwnd, param: param.append(hwnd), hwndChildList) self.z_position_hwnd = hwndChildList[3] hwnd = z_offset_hwnd hwndChildList = [] win32gui.EnumChildWindows(hwnd, lambda hwnd, param: param.append(hwnd), hwndChildList) self.z_offset_button_hwnd = hwndChildList[0] self.z_offset_text_hwnd = hwndChildList[2] self.z_offset_Button = ButtonWrapper(self.z_offset_button_hwnd) self.z_Edit = EditWrapper(self.z_offset_text_hwnd)
def 开始填写基础资料(): for i in 基础资料: if i[1] == 下拉菜单.get(): 客户名称 = i[1] 经营地址 = i[5] 办税人员 = i[3] 办公地区域 = '370212 崂山' 所属区域 = '370212崂山' 电话 = i[4] 纳税人类别 = i[14] + '纳税人' hwndChildList = [] win32gui.EnumChildWindows(None, lambda hwnd,param: param.append(hwnd),hwndChildList) for i in hwndChildList: if '基础资料修改' in win32gui.GetWindowText(i): CRM = i hwndChildList = [] win32gui.EnumChildWindows(CRM, lambda hwnd,param: param.append(hwnd),hwndChildList) 客户名称位置 = hwndChildList[14] 经营地址位置 = hwndChildList[13] 办税人员位置 = hwndChildList[10] 办公地区域位置 = hwndChildList[8] 电话位置 = hwndChildList[44] 纳税人类别位置 = hwndChildList[6] 所属区域位置 = hwndChildList[50] 填信息(客户名称位置,客户名称) 填信息(经营地址位置,经营地址) 填信息(办税人员位置,办税人员) 填信息(办公地区域位置,办公地区域) 填信息(电话位置,电话) 填信息(纳税人类别位置,纳税人类别) 填信息(所属区域位置,所属区域) 点击(hwndChildList[51])
def __get_order_msg(self): # time.sleep(0.005) # 根据 弹出窗口大小判断更快,所以按大小判断 def call_back(handle, dialog_l): _left, _top, _right, _bottom = win32gui.GetWindowRect(handle) # (_right - _left == 300) and (_bottom - _top == 195) # print(win32gui.GetParent(handle)) if win32gui.GetClassName(handle) == "#32770" and \ win32gui.GetWindow(handle, win32con.GW_OWNER) == self.__parent_trade: if (_right - _left == 362) and (_bottom - _top == 204): dialog_l.append(handle) """ 下单 时不论成功失败,肯定在最后有一个 提示 弹框 """ while True: dialog_list = [] win32gui.EnumWindows(call_back, dialog_list) # 获得 每个 dialog 句柄的子句柄,判断出是 提示 弹出窗 prompt_list = [] for dialog in dialog_list: li = [] win32gui.EnumChildWindows( dialog, lambda handle, param: param.append(handle), li) for l in li: txt = win32gui.GetWindowText(l) if txt == "提示": prompt_list.append(dialog) if len(prompt_list) > 1: exit(-1) # 如果没有提示信息窗口,而存在委托窗口,判断无误下单后 退出 if len(prompt_list) == 0: time.sleep(0.01) continue if len(prompt_list) == 1: prompt = prompt_list[0] prompt_info = {} prompt_sons = [] win32gui.EnumChildWindows( prompt, lambda handle, param: param.append(handle), prompt_sons) for prompt_son in prompt_sons: txt = win32gui.GetWindowText(prompt_son) left, top, right, bottom = win32gui.GetWindowRect( prompt_son) if right - left == 332 and bottom - top == 129: prompt_info.update(info=get_item_text(prompt_son)) elif txt == "确定" or txt == "终止": prompt_info.update(confirm_btn=prompt_son) # 提示信息弹出框 发送取消 后,直接退出 win32api.PostMessage(prompt_info["confirm_btn"], win32con.WM_LBUTTONDOWN, None, None) win32api.PostMessage(prompt_info["confirm_btn"], win32con.WM_LBUTTONUP, None, None) return prompt_info["info"]
def 点击新增(): hwndChildList = [] win32gui.EnumChildWindows(None, lambda hwnd,param: param.append(hwnd),hwndChildList) for i in hwndChildList: if '基础资料修改' in win32gui.GetWindowText(i): CRM = i hwndChildList = [] win32gui.EnumChildWindows(CRM, lambda hwnd,param: param.append(hwnd),hwndChildList) 新增 = hwndChildList[15] 点击(新增)
def update_windows(self): """Update window's handlers.""" was_closed = not self.initialized win32gui.EnumWindows(self._get_window_info, None) win32gui.EnumWindows(self._get_key_layout_handle, None) win32gui.EnumChildWindows(self.parent_hwnd, self._get_key_layout_handle, None) win32gui.EnumChildWindows(self.parent_hwnd, self._get_emulator_window_info, None) if was_closed and self.initialized: self.close_app_shortcut = self._get_keyboard_shortcut_for_closing_app() self._get_key_handle_by_nox_version()
def audible(self, verbose=False): self.verbose = verbose # Find process ID of volume mixer for pid in psutil.pids(): # Access gets denied when iterating some processes. F**k it. with fuckit: if psutil.Process(pid).name() == 'SndVol.exe': self.vol_pid = pid if verbose: print('Found volume mixer @ ' + str(self.vol_pid)) # http://stackoverflow.com/a/7006424 # Opens the volume mixer silently if self.vol_pid == 0: self.vol_close = True si = subprocess.STARTUPINFO() si.dwFlags |= subprocess.STARTF_USESHOWWINDOW vol = subprocess.Popen('sndvol', startupinfo=si) # For some reason this fixes when the module can't spit out a PID fast enough time.sleep(0.1) self.vol_pid = vol.pid if verbose: print('Opening volume mixer silently @ ' + str(self.vol_pid)) # Looks through all windows searching for volume mixer window win32gui.EnumWindows(self.enumHandler, None) while self.vol_ready == False: # Scans volume mixer window until applications are found win32gui.EnumChildWindows(self.vol_hwnd, self.childHandler_Wait, None) # Grabs applications found in the volume mixer window win32gui.EnumChildWindows(self.vol_hwnd, self.childHandler, None) # Compares window captions to PIDs and tuples them. for appcap in self.application_captions: for mixcap in self.mixer_captions: if mixcap in appcap[0]: self.playing_sound.append( [appcap[0], psutil.Process(appcap[1]).name()]) # Terminates the volume mixer if it was opened by WinVol, so the user doesn't try to open an invisible window if self.vol_close: subprocess.call('taskkill /F /IM sndvol.exe', creationflags=0x08000000) if verbose: print('Volume mixer closed') return self.playing_sound
def dis_buttons(hwnd:int, dis_timeout:float): def dis_butt(hchild, state): if win32gui.GetWindowLong(hchild, -12) < 12: win32gui.ShowWindow(hchild, state) return True time.sleep(0.01) try: win32gui.EnumChildWindows(hwnd, dis_butt, False) time.sleep(dis_timeout) win32gui.EnumChildWindows(hwnd, dis_butt, True) except: pass
def __init_handle(self): win32gui.PostMessage(self.AfxMDIFrame_hwnd, win32con.WM_KEYDOWN, win32con.VK_F1, 0) win32gui.PostMessage(self.AfxMDIFrame_hwnd, win32con.WM_KEYUP, win32con.VK_F1, 0) win32gui.PostMessage(self.AfxMDIFrame_hwnd, win32con.WM_KEYDOWN, win32con.VK_F2, 0) win32gui.PostMessage(self.AfxMDIFrame_hwnd, win32con.WM_KEYUP, win32con.VK_F2, 0) win32gui.PostMessage(self.AfxMDIFrame_hwnd, win32con.WM_KEYDOWN, win32con.VK_F4, 0) win32gui.PostMessage(self.AfxMDIFrame_hwnd, win32con.WM_KEYUP, win32con.VK_F4, 0) li = [] win32gui.EnumChildWindows(self.AfxMDIFrame_hwnd, lambda handle, param: param.append(handle) if win32gui.GetClassName(handle) == '#32770' else None, li) for i in li: text_whole = [] win32gui.EnumChildWindows(i, lambda handle, param: param.append(win32gui.GetWindowText(handle)) if win32gui.GetWindowText(handle) else None, text_whole) if '查询资金股票' in text_whole and '资金余额' in text_whole and '可用金额' in text_whole: self.hold_panel = HoldPanel(i, self.AfxMDIFrame_hwnd)
def gain_GPS_handle(self): MDIClient_handle = self.get_handle('MDIClient') # todo 这里会有角标越界的bug view_path_name = str(self.radar_view_name).split(" - ")[1] hwndChildList = [] handle = None win32gui.EnumChildWindows(MDIClient_handle, lambda hwnd, param: param.append(hwnd), hwndChildList) for hwnd in hwndChildList: if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd): window_name = win32gui.GetWindowText(hwnd) if window_name and str(view_path_name).find(window_name) >= 0: handle = hwnd break AfxMDIFrame42s_1 = win32gui.FindWindowEx(handle, None, 'AfxMDIFrame42s', None) AfxMDIFrame42s_2 = win32gui.FindWindowEx(AfxMDIFrame42s_1, None, 'AfxMDIFrame42s', None) AfxFrameOrView42 = win32gui.FindWindowEx(AfxMDIFrame42s_2, None, 'AfxFrameOrView42s', None) # win32gui.EnumChildWindows(handle, lambda hwnd, param: param.append(hwnd), hwndChildList) # for hwnd in hwndChildList: # if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWi ndowVisible(hwnd): # window_name = win32gui.GetClassName(hwnd) # if window_name and str(window_name).find('AfxFrameOrView42s') >= 0: # AfxFrameOrView42 = hwnd path = self.win.window_capture('GPS.bmp', AfxFrameOrView42) self.get_gps(path) msctls_statusbar32 = win32gui.FindWindowEx(self.radar_view_handle, None, 'msctls_statusbar32', None) path = self.win.window_capture('H.bmp', msctls_statusbar32) self.get_deepness(path)
def dumpWindow(hwnd): '''Dump all controls from a window into a nested list Useful during development, allowing to you discover the structure of the contents of a window, showing the text and class of all contained controls. Arguments: The window handle of the top level window to dump. Returns A nested list of controls. Each entry consists of the control's hwnd, its text, its class, and its sub-controls, if any. Usage example: replaceDialog = findTopWindow(wantedText='Replace') pprint.pprint(dumpWindow(replaceDialog)) ''' windows = [] try: win32gui.EnumChildWindows(hwnd, _windowEnumerationHandler, windows) except win32gui.error: # No child windows return windows = [list(window) for window in windows] for window in windows: childHwnd, windowText, windowClass = window window_content = dumpWindow(childHwnd) if window_content: window.append(window_content) return windows
def get_hd_from_child_hds(father_hd, some_idx, expect_name): child_hds = [] win32gui.EnumChildWindows(father_hd, lambda hwnd, param: param.append(hwnd), child_hds) names = [win32gui.GetWindowText(each) for each in child_hds] hds = [hex(each) for each in child_hds] print("ChildName List:", names) print("Child Hds List:", hds) if some_idx != None: name = names[some_idx] hd = hds[some_idx] print("The {} Child.".format(some_idx)) print("The Name:{}".format(name)) print("The HD:{}".format(hd)) # 这里松一点,原先是name==expect_name if expect_name == name: return child_hds[some_idx] else: print("窗口不对!") return None else: for name, child_hd in zip(names, child_hds): if expect_name in name: return child_hd
def enum_children(hwnd, results): try: if (win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd)): win32gui.EnumChildWindows(hwnd, handler, results) except Exception: return
def get_tft_window() -> Union[Win32Window, None]: windows = auto.getAllWindows() window = [ window for window in windows if window.title == Wrappers.ACTIVE_WINDOW ] if window: window = window[0] if Wrappers.ACTIVE_WINDOW != Wrappers.LAUNCHER: return window else: children = [] def foreach_child(hwnd: int, lparam: int): children.append(auto.Window(hwnd & 0xFFFFFFFF)) return True win32gui.EnumChildWindows(window._hWnd, enumChildWindowsProc(foreach_child), 0) children_by_name = [ window for window in children if window.title == Wrappers.LAUNCHER_CONTROL ] if children_by_name: return children_by_name[0] else: return None
def enum_child_windows(handle): "Return a list of handles of the child windows of this handle" # this will be filled in the callback function child_windows = [] # callback function for EnumChildWindows def EnumChildProc(hwnd, lparam): "Called for each child - adds child hwnd to list" # append it to our list child_windows.append(hwnd) # return true to keep going return True # define the child proc type enum_child_proc = ctypes.WINFUNCTYPE( ctypes.c_int, # return type ctypes.c_long, # the window handle ctypes.c_long) # extra information # update the proc to the correct type proc = enum_child_proc(EnumChildProc) # loop over all the children (callback called for each) win32gui.EnumChildWindows(handle, proc, 0) return child_windows
def get_children(self, hwnd): children = [] win32gui.EnumChildWindows(hwnd, self._get_child, children) collector = [] for hwnd, x, label in children: collector.append((hwnd, x, label.decode("cp1252"))) return collector
def 登陆(): win32api.ShellExecute(1,'open',找出桌面的CRM(),'','',1) time.sleep(1) 用户名 = 列出子窗口句柄(获得标题对应句柄('登陆 Ver2.0.0.432'))[5] 密码 = 列出子窗口句柄(获得标题对应句柄('登陆 Ver2.0.0.432'))[4] 确定 = 列出子窗口句柄(获得标题对应句柄('登陆 Ver2.0.0.432'))[3] win32gui.SendMessage(用户名,win32con.WM_SETTEXT, 0,'zhangqiang') win32gui.SendMessage(密码,win32con.WM_SETTEXT,0 ,'12345678') win32gui.SendMessage(确定,win32con.WM_LBUTTONDOWN, 0,0) win32gui.PostMessage(确定,win32con.WM_LBUTTONUP, 0,0) hwndChildList = [] # time.sleep(2) 当日提示 = win32gui.FindWindow(None, "当日提示") print(当日提示) if 当日提示: print("找到句柄了") win32gui.EnumChildWindows(当日提示, lambda hwnd,param: param.append(hwnd),hwndChildList) 关闭 = hwndChildList[-1] time.sleep(1) win32gui.SendMessage(关闭,win32con.WM_LBUTTONDOWN, 0,0) win32gui.SendMessage(关闭,win32con.WM_LBUTTONUP, 0,0) else: print("not found")
def __init__(self, classname="BS2CHINAUI", titlename="BlueStacks App Player", stratege=Fgo_stratege(), debug=False): self.hwnd = win32gui.FindWindow(classname, titlename) print(self.hwnd) hwndChildList = [] win32gui.EnumChildWindows(self.hwnd, lambda hwnd, param: param.append(hwnd), hwndChildList) # print(hwndChildList) for i in hwndChildList: if (win32gui.GetClassName(i) == "BlueStacksApp"): self.hwnd = i break # print(self.hwnd) ''' for hwnd in hwndChildList: left, top, right, bot = win32gui.GetWindowRect(hwnd) if right-left == 1280 and bot-top == 720: asf = win32gui.GetWindowText(hwnd) sd = win32gui.GetClassName(hwnd) print(asf) print(sd) self.hwnd = hwnd break ''' # print(right-left , bot-top) self.current_state = None self.image = None self.stratege = stratege self.debug = True self.click_wait_time = 0.01
def get_useful_handle(login_hwnd): child_list = [] win32gui.EnumChildWindows(login_hwnd, lambda hwnd, param: param.append(hwnd), child_list) pos_dic = __get_useful_position(login_hwnd) handles = {} for child in child_list: window_rect = win32gui.GetWindowRect(child) if win32gui.GetClassName(child) == "Edit": if pos_in_window_rect(pos_dic["username_pos"], window_rect): handles.update(username_hwnd=child) elif pos_in_window_rect(pos_dic["password_pos"], window_rect): handles.update(password_hwnd=child) elif pos_in_window_rect(pos_dic["identify_pos"], window_rect): handles.update(identify_hwnd=child) # elif win32gui.GetClassName(child) == "ComboBox": # if pos_in_window_rect(pos_dic["mode_pos"], window_rect): # handles.update(mode_hwnd=child) elif win32gui.GetClassName(child) == "Static": if pos_in_window_rect(pos_dic["identify_img"], window_rect): handles.update(identify_img_hwnd=child) elif win32gui.GetClassName(child) == "Button": if pos_in_window_rect(pos_dic["login_btn_pos"], window_rect): handles.update(login_btn_hwnd=child) return handles
def get_window(title_pattern: str, parent: Optional[Handle] = None) -> Tuple[Handle, str]: reg = re.compile(title_pattern) hwnd = Handle(0) title = '' def handler(_hwnd: Handle, _): nonlocal hwnd nonlocal title title = win32gui.GetWindowText(_hwnd) if reg.search(title): hwnd = _hwnd return False try: win32gui.EnumChildWindows(parent, handler, None) except BaseException as e: # swallow the error that will be mysteriously thrown when breaking the window enumeration by returning False # in handler, its error code can be 0 or 126 if getattr(e, 'winerror', -1) not in (0, 126): raise return hwnd, title
def findWindows(classname=None, title=None, mode=0): ''' :param classname: :param title: :param mode: 0:默认模糊查找, 1:精确查找 :return: ''' childs = [] hwnd = win32gui.GetDesktopWindow() def all_ok(hwnd, param): print(hwnd, win32gui.GetWindowText(hwnd), win32gui.GetClassName(hwnd)) if mode == 1: if win32gui.GetClassName( hwnd) == classname and win32gui.GetWindowText( title) == title: print(hwnd, win32gui.GetWindowText(hwnd), win32gui.GetClassName(hwnd)) childs.append(hwnd) else: if win32gui.GetClassName( hwnd) == classname or win32gui.GetWindowText( title) == title: print(hwnd, win32gui.GetWindowText(hwnd), win32gui.GetClassName(hwnd)) childs.append(hwnd) return True win32gui.EnumChildWindows(hwnd, all_ok, None) return childs
def login(self): global username_hwnd, password_hwnd, comm_password_hwnd, login_btn_hwnd if login_window_open(): return else: # 打开登录窗口 self.__open_login_windows() # 找到各个句柄 child_list = [] win32gui.EnumChildWindows(self.__login_hwnd, lambda hwnd, param: param.append(hwnd), child_list) # TODO 暂时根据在句柄列表中的 index 位置判定 username_hwnd = child_list[1] password_hwnd = child_list[2] comm_password_hwnd = child_list[4] login_btn_hwnd = child_list[24] # for child in child_list: # if pos_in_window_rect(self.__pos_username_input, win32gui.GetWindowRect(self.__login_hwnd), child): # username_hwnd = child # elif pos_in_window_rect(self.__pos_password_input, win32gui.GetWindowRect(self.__login_hwnd), child): # password_hwnd = child # elif pos_in_window_rect(self.__pos_comm_pw_input, win32gui.GetWindowRect(self.__login_hwnd), child): # comm_password_hwnd = child # elif pos_in_window_rect(self.__pos_login_button, win32gui.GetWindowRect(self.__login_hwnd), child): # login_btn_hwnd = child # 使用 windows 消息机制 登录 win32gui.SendMessage(username_hwnd, win32con.WM_SETTEXT, None, self.__username) win32gui.SendMessage(password_hwnd, win32con.WM_SETTEXT, None, self.__password) win32gui.SendMessage(comm_password_hwnd, win32con.WM_SETTEXT, None, self.__password) win32gui.SendMessage(login_btn_hwnd, win32con.WM_LBUTTONDOWN, None, None) win32gui.SendMessage(login_btn_hwnd, win32con.WM_LBUTTONUP, None, None) time.sleep(6)
def searchChildWindows(currentHwnd): results = [] childWindows = [] try: win32gui.EnumChildWindows(currentHwnd, _windowEnumerationHandler, childWindows) except win32gui.error: # This seems to mean that the control *cannot* have child windows, # i.e. not a container. return for childHwnd, windowText, windowClass in childWindows: descendentMatchingHwnds = searchChildWindows(childHwnd) if descendentMatchingHwnds: results += descendentMatchingHwnds if wantedText and \ not _normaliseText(wantedText) in _normaliseText(windowText): continue if wantedClass and \ not windowClass == wantedClass: continue if selectionFunction and \ not selectionFunction(childHwnd): continue results.append(childHwnd) return results
def get_sub_handles(self): """通过父句柄获取子句柄""" sub_handles = [] win32gui.EnumChildWindows(self.handle, self.call_back, sub_handles) print(sub_handles) return sub_handles
def get_child_windows(parent): if not parent: return hwndChildList = [] win32gui.EnumChildWindows(parent, lambda hwnd, param: param.append(hwnd), hwndChildList) return hwndChildList
def 基础资料判断(): for i in 基础资料: if i[1] == 下拉菜单.get(): 判断税号 = i[2] hwndChildList = [] win32gui.EnumChildWindows(None, lambda hwnd,param: param.append(hwnd),hwndChildList) for i in hwndChildList: if '基础资料修改' in win32gui.GetWindowText(i): CRM = i hwndChildList = [] win32gui.EnumChildWindows(CRM, lambda hwnd,param: param.append(hwnd),hwndChildList) 需判断的识别号 = hwndChildList[58] 进行判断 = hwndChildList[54] 填信息(需判断的识别号,判断税号) 点击(进行判断)
def getAllChirdWindows(self, handle): hwndChildList = [] win32gui.EnumChildWindows(handle, lambda hwnd, param: param.append(hwnd), hwndChildList) allchildwindows = hwndChildList return allchildwindows
def callback(hwnd, lparam): title = win32gui.GetWindowText(hwnd).lower() for window in self.to_close: if window in title: win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) print("Closed window ({})".format(title)) for window in self.clicks: if window in title: self._windows[hwnd] = { "matches": self.clicks[window], "to_click": [], "buttons": [] } try: win32gui.EnumChildWindows(hwnd, self.foreach_child(), hwnd) except Exception: print("EnumChildWindows failed, moving on.") for button_toclick in self._windows[hwnd]['to_click']: for button in self._windows[hwnd]['buttons']: if button_toclick in button['text']: win32gui.SetForegroundWindow(button['handle']) win32gui.SendMessage(button['handle'], win32con.BM_CLICK, 0, 0) print("Clicked on button ({} / {})".format( title, button['text'])) del self._windows[hwnd] return True