from pywinauto.application import Application import pywinauto import warnings # ignoring a lot of warnings to run python in 64bit mode for # 64bit applications and vice versa for 32bit. warnings.filterwarnings('ignore') pywinauto.actionlogger.disable() list_of_visible_windows = [] windows = pywinauto.findwindows.find_windows(enabled_only=True, visible_only=True) for handle in windows: a = Application() a.connect(handle=handle) w = a.windows()[0] window = w.element_info #print("name: %s" % window.name) #print("pid: %d" % window.process_id) #print("visible: %s" % window.visible) if window.visible: list_of_visible_windows.append(window) for w in list_of_visible_windows: print((w.process_id, w.name))
from pywinauto.application import Application import pywinauto.mouse as mouse import pywinauto.keyboard as keyboard app = Application(backend="uia").start('notepad.exe') app.windows() #app.UntitledNotepad.type_keys("%FX") dlg = app['Untitled - Notepad'] #dlg.menu_select("View -> Status Bar") #dlg.menu_select("File -> Save as") dlg.menu_select("Edit -> Replace") dlg.Replace.Cancel.click() d.print_control_identifiers() #dlg.Edit.type_keys('Welcome to Medium') # D:\shortcall\twitter_v3\twitter_v3-01 dlg.set_focus() keyboard.send_keys('Hello')
app = Application().connect(path=r"c:\windows\system32\notepad.exe") # There are many different ways of doing this. # The most common will be using item or attribute access to select a # dialog based on it’s title. e.g dlg = app.Notepad dlg = app['Notepad'] # This will return the window that has the highest Z-Order # of the top-level windows of the application. dlg = app.top_window() # If this is not enough control then you can use the same parameters # as can be passed to findwindows.find_windows() e.g. dlg = app.window(title_re="Page Setup", class_name="#32770") # Finally to have the most control you can use dialogs = app.windows() # this will return a list of all the visible, enabled, top level windows of the # application. You can then use some of the methods in handleprops # module select the dialog you want. # Once you have the handle you need then use #app.window(handle=win) # If the title of the dialog is very long - then attribute # access might be very long to type, in those cases it is usually easier to use app.window(title_re=".*Part of Title.*") # There are a number of ways to specify a control, the simplest are app.dlg.control app['dlg']['control']