### Starting an Application Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait_cpu_usage_lower Illustrates how to start a new application process. This includes specifying the command line, setting a timeout for the start operation, and optionally waiting for the application to become idle. ```python app.start("notepad.exe", timeout=10, wait_for_idle=True) ``` -------------------------------- ### Start Notepad and Type Keys Source: https://pywinauto.readthedocs.io/en/latest/index.html This snippet demonstrates how to start a Notepad application instance using the 'uia' backend and send keyboard shortcuts to it. ```python >>> from pywinauto.application import Application >>> app = Application(backend="uia").start("notepad.exe") >>> app.UntitledNotepad.type_keys("%FX") ``` -------------------------------- ### Automate Notepad from Command Line Source: https://pywinauto.readthedocs.io/en/latest/getting_started.html This example demonstrates how to start Notepad, interact with its menu, print control identifiers for a dialog, type text into an edit control, and exit the application. It showcases basic pywinauto functionalities for Windows automation. ```python >>> from pywinauto import application >>> app = application.Application() >>> app.start("Notepad.exe") >>> app.UntitledNotepad.draw_outline() >>> app.UntitledNotepad.menu_select("Edit -> Replace") >>> app.Replace.print_control_identifiers() Control Identifiers: Dialog - 'Replace' (L179, T174, R657, B409) ['ReplaceDialog', 'Dialog', 'Replace'] child_window(title="Replace", class_name="#32770") | | | Static - 'Fi&nd what:' (L196, T230, R292, B246) | ['Fi&nd what:Static', 'Fi&nd what:', 'Static', 'Static0', 'Static1'] | child_window(title="Fi&nd what:", class_name="Static") | | Edit - '' (L296, T226, R524, B250) | ['Fi&nd what:Edit', 'Edit', 'Edit0', 'Edit1'] | child_window(class_name="Edit") | | Static - 'Re&place with:' (L196, T264, R292, B280) | ['Re&place with:', 'Re&place with:Static', 'Static2'] | child_window(title="Re&place with:", class_name="Static") | | Edit - '' (L296, T260, R524, B284) | ['Edit2', 'Re&place with:Edit'] | child_window(class_name="Edit") | | CheckBox - 'Match &whole word only' (L198, T304, R406, B328) | ['CheckBox', 'Match &whole word onlyCheckBox', 'Match &whole word only', 'CheckBox0', 'CheckBox1'] | child_window(title="Match &whole word only", class_name="Button") | | CheckBox - 'Match &case' (L198, T336, R316, B360) | ['CheckBox2', 'Match &case', 'Match &caseCheckBox'] | child_window(title="Match &case", class_name="Button") | | Button - '&Find Next' (L536, T220, R636, B248) | ['&Find Next', '&Find NextButton', 'Button', 'Button0', 'Button1'] | child_window(title="&Find Next", class_name="Button") | | Button - '&Replace' (L536, T254, R636, B282) | ['&ReplaceButton', '&Replace', 'Button2'] | child_window(title="&Replace", class_name="Button") | | Button - 'Replace &All' (L536, T288, R636, B316) | ['Replace &AllButton', 'Replace &All', 'Button3'] | child_window(title="Replace &All", class_name="Button") | | Button - 'Cancel' (L536, T322, R636, B350) | ['CancelButton', 'Cancel', 'Button4'] | child_window(title="Cancel", class_name="Button") | | Button - '&Help' (L536, T362, R636, B390) | ['&Help', '&HelpButton', 'Button5'] | child_window(title="&Help", class_name="Button") | | Static - '' (L196, T364, R198, B366) | ['ReplaceStatic', 'Static3'] | child_window(class_name="Static") >>> app.Replace.Cancel.click() >>> app.UntitledNotepad.Edit.type_keys("Hi from Python interactive prompt %s" % str(dir()), with_spaces = True) >>> app.UntitledNotepad.menu_select("File -> Exit") >>> app.Notepad.DontSave.click() >>> ``` -------------------------------- ### Start Notepad Application with UIA Backend Source: https://pywinauto.readthedocs.io/en/latest/getting_started.html Starts a new instance of Notepad.exe using the 'uia' backend and obtains a dialog specification for the main window. ```python from pywinauto.application import Application app = Application(backend="uia").start('notepad.exe') # describe the window inside Notepad.exe process dlg_spec = app.UntitledNotepad # wait till the window is really open actionable_dlg = dlg_spec.wait('visible') ``` -------------------------------- ### Start and Connect to an Application Source: https://pywinauto.readthedocs.io/en/latest/HISTORY.html Use static methods to start or connect to an application, returning an initialized Application instance. These methods are factory methods implemented in terms of start_() and connect(). ```Python from pywinauto.application import Application notepad = Application.start("notepad") same_notepad = Application.connect(path = "notepad") ``` -------------------------------- ### Run Example with Language Argument Source: https://pywinauto.readthedocs.io/en/latest/HISTORY.html Use this command to run an example script with language-specific application data for localization testing. This requires a .pkl file containing the application data. ```bash examples\notepad_fast.py language ``` -------------------------------- ### Start an Application Source: https://pywinauto.readthedocs.io/en/latest/HowTo.html Use the `start` method when the application is not running and needs to be launched. The `cmd_line` parameter specifies the executable and its arguments. ```python app = Application().start(r"c:\path\to\your\application -a -n -y --arguments") ``` -------------------------------- ### Starting an Application Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html Shows how to start a new application process. Options include specifying a working directory, creating a new console, and controlling whether to wait for the application to become idle. ```python app.start("notepad.exe") app.start("C:\\Program Files\\YourApp\\app.exe", work_dir="C:\\Users\\User") app.start("notepad.exe", create_new_console=True) app.start("notepad.exe", wait_for_idle=False) ``` -------------------------------- ### Starting an Application Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=print_control_identifiers Starts a new instance of an application. Options include specifying a working directory, creating a new console, and waiting for the application to become idle. ```python app.start("notepad.exe") app.start("C:\\path\\to\\app.exe", wait_for_idle=False) app.start("C:\\path\\to\\app.exe", create_new_console=True, work_dir="C:\\Users\\") ``` -------------------------------- ### Start Application with MS UI Automation Backend Source: https://pywinauto.readthedocs.io/en/latest/HISTORY.html Use this to start an application with the MS UI Automation backend. Ensure 'your_app.exe' is replaced with the actual application executable. ```python app = Application(backend='uia').start('your_app.exe') ``` -------------------------------- ### Starting an Application Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait_not Starts a new application instance using the specified command line. Supports optional parameters for timeout, retry interval, creating a new console, and waiting for idle. ```python app.start("notepad.exe") app.start("C:\\Program Files\\YourApp\\app.exe", wait_for_idle=False) app.start("C:\\Program Files\\YourApp\\app.exe", timeout=5, retry_interval=0.5) ``` -------------------------------- ### Starting an Application Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait Start a new application process using its command line. Options include setting a timeout, retry interval, working directory, and whether to create a new console. ```python app.start("notepad.exe") app.start("C:\\path\\to\\app.exe", timeout=10, retry_interval=0.5, create_new_console=True, work_dir="C:\\Users\\User") ``` -------------------------------- ### Pywinauto GUI Automation Example Source: https://pywinauto.readthedocs.io/en/latest/index.html This example demonstrates the pywinauto approach, which is more object-oriented and Pythonic. It allows for more intuitive interaction with application elements through direct attribute access and method calls. ```python win = app.UntitledNotepad win.menu_select("Format->Font") app.Font.OK.click() ``` -------------------------------- ### Handling Application Start Errors Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=print_control_identifiers This exception is raised when there is a problem starting the application. ```python try: app.start("non_existent_app.exe") except pywinauto.application.AppStartError as e: print(f"Failed to start application: {e}") ``` -------------------------------- ### Menu Item Interaction Example Source: https://pywinauto.readthedocs.io/en/latest/TODO.html This example demonstrates a proposed change to how menu items are accessed and interacted with in pywinauto. It suggests a more object-oriented approach for selecting and querying menu items. ```python dlg.Menu("blah->blah").select() ``` ```python dlg.Menu.Blah.Blah.select() ``` ```python dlg.Menu.Blah.Blah.IsChecked() ``` ```python dlg.Menu.Blah.Blah.IsEnabled() ``` -------------------------------- ### Traditional GUI Automation Example Source: https://pywinauto.readthedocs.io/en/latest/index.html This example shows a common approach in older GUI automation tools, which often involves finding windows by title and class, and then sending key presses or interacting with dialogs using specific functions. ```python window = findwindow(title = "Untitled - Notepad", class = "Notepad") SendKeys(window, "%OF") # Format -> Font fontdialog = findwindow("title = "Font") buttonClick(fontdialog, "OK") ``` -------------------------------- ### get_toolbar() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the toolbar control. ```APIDOC ## get_toolbar() ### Description Gets the toolbar control. ### Method (pywinauto.controls.hwndwrapper.HwndWrapper method) ``` -------------------------------- ### get_sel_start Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the start position of the selection in a Trackbar control. ```APIDOC ## get_sel_start() ### Description Retrieves the start position of the selected range in a Trackbar control. ### Method N/A (Method of TrackbarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **int**: The start position of the selection. ``` -------------------------------- ### Application.start Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait_cpu_usage_lower Start the application as specified by cmd_line. This method launches a new instance of the application. ```APIDOC ## Application.start ### Description Start the application as specified by cmd_line. ### Method start(cmd_line, timeout=None, retry_interval=None, create_new_console=False, wait_for_idle=True, work_dir=None) ### Parameters #### Arguments - **cmd_line** (str) - The command line to start the application. - **timeout** (int, optional) - The timeout in seconds for the application to start. - **retry_interval** (int, optional) - The interval in seconds between retries if the application does not start. - **create_new_console** (bool, optional) - If True, creates a new console for the application. Defaults to False. - **wait_for_idle** (bool, optional) - If True, waits for the application to become idle after starting. Defaults to True. - **work_dir** (str, optional) - The working directory for the application. ``` -------------------------------- ### TabControlWrapper Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.controls.common_controls.html Wraps the Windows Tab common control, providing methods to get tab counts, select tabs, retrieve tab rectangles and texts, and get client rectangles. ```APIDOC ## TabControlWrapper ### Description Class that wraps Windows Tab common control. ### Methods - `GetSelectedTab()`: Returns the index of the selected tab. - `GetTabRect(tab_index)`: Returns the rectangle to the tab specified by tab_index. - `GetTabText(tab_index)`: Returns the text of the tab. - `RowCount()`: Returns the number of rows of tabs. - `Select(tab)`: Selects the specified tab on the tab control. - `TabCount()`: Returns the number of tabs. - `client_rects()`: Returns the client rectangles for the Tab Control. - `get_properties()`: Returns the properties of the TabControl as a Dictionary. - `get_selected_tab()`: Returns the index of the selected tab. - `get_tab_rect(tab_index)`: Returns the rectangle to the tab specified by tab_index. - `get_tab_text(tab_index)`: Returns the text of the tab. - `row_count()`: Returns the number of rows of tabs. - `select(tab)`: Selects the specified tab on the tab control. - `tab_count()`: Returns the number of tabs. - `texts()`: Returns the texts of the Tab Control. ### Properties - `friendlyclassname`: 'TabControl' - `writable_props`: Extends default properties list. - `windowclasses`: ['SysTabControl32', 'WindowsForms\\d*\\.SysTabControl32\\..*'] ``` -------------------------------- ### Connecting to a Running Application Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html Demonstrates how to connect to an already running process using various identifiers like process ID, window handle, or path. A timeout can be specified for process startup if a path is provided. ```python app.connect(process=1234) app.connect(handle=123456) app.connect(path='C:\\Program Files\\YourApp\\app.exe') app.connect(path='C:\\Program Files\\YourApp\\app.exe', timeout=10) ``` -------------------------------- ### Writing to Dialogs Example Source: https://pywinauto.readthedocs.io/en/latest/dev_notes.html Illustrates methods for writing to dialogs, including a direct XML file approach and a more complex scenario requiring confirmation of the correct dialog. ```python app.MainWin.MenuSelect("Something That->Loads a Dialog") app.Dlg._write("dlg.xml") ``` ```python app.PageSetup.Printer.Click() app.PageSetup._write("pagesetup.xml") ``` -------------------------------- ### FuzzyDict Initialization and Basic Usage Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.fuzzydict.html Demonstrates how to initialize a FuzzyDict with items and perform basic lookups. If an exact match is not found, it attempts a fuzzy match. A KeyError is raised if no sufficiently close match is found. ```python fuzzywuzzy = FuzzyDict({"hello" : "World", "Hiya" : 2, "Here you are" : 3}) fuzzywuzzy['Me again'] = [1,2,3] fuzzywuzzy['Hi'] # next one doesn't match well enough - so a key error is raised fuzzywuzzy['There'] fuzzywuzzy['you are'] fuzzywuzzy['again'] ``` -------------------------------- ### Basic Key Press and Hold Example Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html Demonstrates how to press and hold a key, type text, and then release the key. This is useful for simulating actions like typing in all caps. ```python send_keys("{VK_SHIFT down}" "pywinauto" "{VK_SHIFT up}") # to type PYWINAUTO ``` ```python send_keys("{h down}" "{e down}" "{h up}" "{e up}" "llo") # to type hello ``` -------------------------------- ### get_properties Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the properties of a control. ```APIDOC ## get_properties() ### Description Retrieves all available properties of a control. ### Method N/A (Method of BaseWrapper, TabControlWrapper, TreeViewWrapper, Menu, MenuItem, ComboBoxWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **dict**: A dictionary containing the control's properties. ``` -------------------------------- ### Connect to a Running Application by Executable Path Source: https://pywinauto.readthedocs.io/en/latest/HowTo.html Use the `connect` method with the `path` parameter to attach to an already running application by specifying the path to its executable. ```python app = Application().connect(path=r"c:\windows\system32\notepad.exe") ``` -------------------------------- ### Predefined Timing Settings Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.timings.html Use these methods to quickly set common timing configurations. ```python timings.Timings.fast() ``` ```python timings.Timings.defaults() ``` ```python timings.Timings.slow() ``` -------------------------------- ### get_position Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the position of a control. ```APIDOC ## get_position() ### Description Retrieves the current position of a control on the screen. ### Method N/A (Method of PagerWrapper, ProgressWrapper, TrackbarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **tuple**: A tuple representing the (x, y) coordinates of the control's top-left corner. ``` -------------------------------- ### enable Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.actionlogger.html Enables pywinauto logging actions. ```APIDOC ## enable() ### Description Enable pywinauto logging actions. ### Function Signature `pywinauto.actionlogger.enable()` ``` -------------------------------- ### get_tab_text() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the text of a tab control. ```APIDOC ## get_tab_text() ### Description Gets the text of a tab control. ### Method (pywinauto.controls.common_controls.TabControlWrapper method) ``` -------------------------------- ### get_tab_rect() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the rectangle of a tab control. ```APIDOC ## get_tab_rect() ### Description Gets the rectangle of a tab control. ### Method (pywinauto.controls.common_controls.TabControlWrapper method) ``` -------------------------------- ### Connect to a Running Application by Window Handle Source: https://pywinauto.readthedocs.io/en/latest/HowTo.html Use the `connect` method with the `handle` parameter to attach to an already running application using its main window's handle. ```python app = Application().connect(handle=0x010f0c) ``` -------------------------------- ### Launch Calculator and Access with Desktop Object Source: https://pywinauto.readthedocs.io/en/latest/getting_started.html Launches the Calculator application using subprocess and then connects to it using the Desktop object with the 'uia' backend. Waits for the Calculator window to be visible. ```python from subprocess import Popen from pywinauto import Desktop Popen('calc.exe', shell=True) dlg = Desktop(backend="uia").Calculator dlg.wait('visible') ``` -------------------------------- ### get_state Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the state of a Progress control. ```APIDOC ## get_state() ### Description Retrieves the current state of a Progress control (e.g., its value). ### Method N/A (Method of ProgressWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **int**: The state or value of the progress control. ``` -------------------------------- ### get_selection Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the current selection of a control. ```APIDOC ## get_selection() ### Description Retrieves the current selection from a control. ### Method N/A (Method of UIAWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **object**: The selected item or value. ``` -------------------------------- ### Accessing Dialogs Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html Examples of how to access dialogs within an application instance using different methods. ```python dlg = app.YourDialogTitle dlg = app.child_window(title="your title", classname="your class", ...) dlg = app['Your Dialog Title'] ``` -------------------------------- ### get_range Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the range of a UpDown control. ```APIDOC ## get_range() ### Description Retrieves the valid range (minimum and maximum values) of a UpDown control. ### Method N/A (Method of UpDownWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **tuple**: A tuple containing the minimum and maximum values. ``` -------------------------------- ### get_non_text_control_name Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the name of a non-text control. ```APIDOC ## get_non_text_control_name() ### Description Retrieves the name of a control that does not display text. ### Method N/A (Function in pywinauto.findbestmatch) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **str**: The name of the non-text control. ``` -------------------------------- ### get_items Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets all items from a ListView control. ```APIDOC ## get_items() ### Description Retrieves all items from a ListView control. ### Method N/A (Method of ListViewWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **list**: A list of items. ``` -------------------------------- ### Connect to Application using Static Method Source: https://pywinauto.readthedocs.io/en/latest/HISTORY.html Use the static `connect()` method to establish a connection to an application. This simplifies the connection process compared to the older `connect_()` method. ```python app = Application.connect(title = 'Find') app.Find.Close.Click() app.NotePad.MenuSelect("File->Exit") ``` -------------------------------- ### Connecting to a Running Application Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait_cpu_usage_lower Shows how to connect to an already running process. This method can use process ID, window handle, or the path to the executable. A timeout can be specified for the connection attempt. ```python app.connect(process=1234, timeout=10) app.connect(handle=123456, timeout=10) app.connect(path='C:\\path\\to\\your\\app.exe', timeout=10) ``` -------------------------------- ### get_id Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the ID of a Calendar control. ```APIDOC ## get_id() ### Description Retrieves the identifier of a Calendar control. ### Method N/A (Method of CalendarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **int**: The control ID. ``` -------------------------------- ### Application.connect Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait_cpu_usage_lower Connect to an already running process. This method allows you to attach to an existing application instance using its process ID, window handle, or executable path. ```APIDOC ## Application.connect ### Description Connect to an already running process. The action is performed according to only one of parameters. ### Method connect(**kwargs) ### Parameters #### Keyword Arguments - **process** (int) - A process ID of the target. - **handle** (int) - A window handle of the target. - **path** (str) - A path used to launch the target. - **timeout** (int, optional) - A timeout for process start (relevant if path is specified). See also: `pywinauto.findwindows.find_elements()` - the keyword arguments that are also can be used instead of **process**, **handle** or **path** ``` -------------------------------- ### get_header_controls Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets all header controls of a ListView. ```APIDOC ## get_header_controls() ### Description Retrieves all header controls associated with a ListView. ### Method N/A (Method of ListViewWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **list**: A list of HeaderWrapper objects. ``` -------------------------------- ### Control Resolution Example Source: https://pywinauto.readthedocs.io/en/latest/index.html Illustrates pywinauto's attribute-based control resolution, showing how it searches for windows and controls by title. ```python myapp.Notepad # looks for a Window/Dialog of your app that has a title 'similar' # to "Notepad" myapp.PageSetup.OK # looks first for a dialog with a title like "PageSetup" # then it looks for a control on that dialog with a title # like "OK" ``` -------------------------------- ### get_header_control Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the header control of a ListView. ```APIDOC ## get_header_control() ### Description Retrieves the header control associated with a ListView. ### Method N/A (Method of ListViewWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **HeaderWrapper**: The header control. ``` -------------------------------- ### Create Detailed Window Specification Source: https://pywinauto.readthedocs.io/en/latest/getting_started.html Creates a detailed window specification for a Notepad window with a specific title. It also shows how to get the wrapper object for the actual window/control. ```python >>> dlg_spec = app.window(title='Untitled - Notepad') >>> dlg_spec >>> dlg_spec.wrapper_object() ``` -------------------------------- ### get_column Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets a column from a ListView control. ```APIDOC ## get_column() ### Description Retrieves a specific column from a ListView control. ### Method N/A (Method of ListViewWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **object**: The column information. ``` -------------------------------- ### get_child Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets a child element or item. ```APIDOC ## get_child() ### Description Retrieves a child element or item from a control. ### Method N/A (Method of _treeview_element, TreeItemWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **ControlWrapper**: The child control. ``` -------------------------------- ### Application Class Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html The Application class is the main entry point for users. It allows starting or connecting to an application and then accessing its windows and controls. ```APIDOC ## class Application Represents an application. ### Methods * **__getitem__(key)**: Find the specified dialog of the application. * **active()**: Return WindowSpecification for an active window of the application. * **connect(**kwargs**)**: Connect to an already running process. Parameters: process, handle, path, timeout. See also `pywinauto.findwindows.find_elements()`. * **cpu_usage(interval=None)**: Return CPU usage percent during specified number of seconds. * **is64bit()**: Return True if running process is 64-bit. * **is_process_running()**: Check that process is running. Return True if process is running otherwise - False. * **kill(soft=False)**: Try to close (optional) and kill the application. * **start(cmd_line, timeout=None, retry_interval=None, create_new_console=False, wait_for_idle=True, work_dir=None)**: Start the application as specified by cmd_line. * **top_window()**: Return WindowSpecification for a current top window of the application. * **wait_cpu_usage_lower(threshold=2.5, timeout=None, usage_interval=None)**: Wait until process CPU usage percentage is less than the specified threshold. * **wait_for_process_exit(timeout=None, retry_interval=None)**: Waits for process to exit until timeout reaches. Raises TimeoutError exception if timeout was reached. * **window(**kwargs**)**: Return a window of the application. You can specify the same parameters as findwindows.find_windows. It will add the process parameter to ensure that the window is from the current process. See `pywinauto.findwindows.find_elements()` for the full parameters description. * **windows(**kwargs**)**: Return a list of wrapped top level windows of the application. ``` -------------------------------- ### get_button Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets a button from a Toolbar control. ```APIDOC ## get_button() ### Description Retrieves a specific button from a Toolbar control. ### Method N/A (Method of ToolbarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **ButtonWrapper**: The button control. ``` -------------------------------- ### Best Match Identifier Example Source: https://pywinauto.readthedocs.io/en/latest/HowTo.html Demonstrates how pywinauto can match a provided identifier against available control identifiers, even if it's not an exact match. This allows for more flexible control selection. ```python (Pdb) print app.PageSetup.Margins.window_text() Margins (inches) (Pdb) print app.PageSetup.MarginsGroupBox.window_text() Margins (inches) ``` -------------------------------- ### Menu Selection and Control Interaction Source: https://pywinauto.readthedocs.io/en/latest/index.html Demonstrates selecting a menu item and interacting with controls in a dialog, highlighting pywinauto's delayed attribute resolution. ```python app.UntitledNotepad.menu_select("File->SaveAs") app.SaveAs.ComboBox5.select("UTF-8") app.SaveAs.edit1.set_text("Example-utf8.txt") app.SaveAs.Save.click() ``` -------------------------------- ### GetTabText() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the text of a tab in a tab control. ```APIDOC ## GetTabText() ### Description Gets the text of a tab in a tab control. ### Method (pywinauto.controls.common_controls.TabControlWrapper method) ``` -------------------------------- ### Create Window Specification with Regex and Combined Criteria Source: https://pywinauto.readthedocs.io/en/latest/getting_started.html Shows how to create window specifications using regular expressions for titles and combining multiple criteria like auto_id and control_type. ```python # can be multi-level app.window(title_re='.* - Notepad$').window(class_name='Edit') # can combine criteria dlg = Desktop(backend="uia").Calculator dlg.window(auto_id='num8Button', control_type='Button') ``` -------------------------------- ### GetTabRect() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the rectangle of a tab in a tab control. ```APIDOC ## GetTabRect() ### Description Gets the rectangle of a tab in a tab control. ### Method (pywinauto.controls.common_controls.TabControlWrapper method) ``` -------------------------------- ### GetState() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the state of a progress bar control. ```APIDOC ## GetState() ### Description Gets the state of a progress bar control. ### Method (pywinauto.controls.common_controls.ProgressWrapper method) ``` -------------------------------- ### Connect to a Running Application by Title and Class Source: https://pywinauto.readthedocs.io/en/latest/HowTo.html Use the `connect` method with `title_re` and `class_name` parameters to connect to a specific application window based on its title and class name. ```python app = Application().connect(title_re=".*Notepad", class_name="Notepad") ``` -------------------------------- ### Running Scripts with pywinauto.exe Source: https://pywinauto.readthedocs.io/en/latest/TODO.html This snippet shows a potential command-line interface for running pywinauto scripts. It suggests creating a Py2exe wrapper to make pywinauto accessible without a Python installation. ```text pywinauto.exe yourscript.py ``` -------------------------------- ### GetFormatName() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the name of a clipboard data format. ```APIDOC ## GetFormatName() ### Description Gets the name of a clipboard data format. ### Method (in module pywinauto.clipboard) ``` -------------------------------- ### Application Class Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait_not The Application class is the main entry point for pywinauto. Users instantiate this class to interact with an application. It provides methods to start, connect to, and manage application processes, as well as access its windows and controls. ```APIDOC class pywinauto.application.Application(_backend='win32', _datafilename=None, _allow_magic_lookup=True_) Represents an application. __getattribute__(attr_name) __getitem__(key) Find the specified dialog of the application. GetMatchHistoryItem(index) Should not be used - part of application data implementation. WriteAppData(filename) Should not be used - part of application data implementation. active() Return WindowSpecification for an active window of the application. connect(**kwargs) Connect to an already running process. The action is performed according to only one of parameters: Parameters: * process – a process ID of the target * handle – a window handle of the target * path – a path used to launch the target * timeout – a timeout for process start (relevant if path is specified) See also: `pywinauto.findwindows.find_elements()` - the keyword arguments that are also can be used instead of **process** , **handle** or **path**. cpu_usage(interval=None) Return CPU usage percent during specified number of seconds. is64bit() Return True if running process is 64-bit. is_process_running() Check that process is running. Can be called before start/connect. Return True if process is running otherwise - False. kill(soft=False) Try to close (optional) and kill the application. Dialogs may pop up asking to save data - but the application will be killed anyway - you will not be able to click the buttons. This should only be used when it is OK to kill the process like you would do in task manager. start(cmd_line, timeout=None, retry_interval=None, create_new_console=False, wait_for_idle=True, work_dir=None) Start the application as specified by cmd_line. top_window() Return WindowSpecification for a current top window of the application. wait_cpu_usage_lower(threshold=2.5, timeout=None, usage_interval=None) Wait until process CPU usage percentage is less than the specified threshold. wait_for_process_exit(timeout=None, retry_interval=None) Waits for process to exit until timeout reaches. Raises TimeoutError exception if timeout was reached. window(**kwargs) Return a window of the application. You can specify the same parameters as findwindows.find_windows. It will add the process parameter to ensure that the window is from the current process. See `pywinauto.findwindows.find_elements()` for the full parameters description. windows(**kwargs) Return a list of wrapped top level windows of the application. ``` -------------------------------- ### GetColumnText() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the text of a column in a header control. ```APIDOC ## GetColumnText() ### Description Gets the text of a column in a header control. ### Method (pywinauto.controls.common_controls.HeaderWrapper method) ``` -------------------------------- ### Accessing Controls Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html Examples of how to access controls within a dialog using different methods. ```python ctrl = dlg.YourControlTitle ctrl = dlg.child_window(title="Your control", classname="Button", ...) ctrl = dlg["Your control"] ``` -------------------------------- ### GetColumnRectangle() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the rectangle of a column in a header control. ```APIDOC ## GetColumnRectangle() ### Description Gets the rectangle of a column in a header control. ### Method (pywinauto.controls.common_controls.HeaderWrapper method) ``` -------------------------------- ### Attribute Access Example Source: https://pywinauto.readthedocs.io/en/latest/dev_notes.html Demonstrates delayed resolution for attribute access in pywinauto to handle potential timing issues when interacting with dialogs and controls. ```python app.dlg.control.action() ``` ```python # open the Printer setup dialog (which has “Page Setup” as title) app.PageSetup.Printer.Click() # if this runs too quickly it actually finds the current page setup dialog # before the next dialog opens, but that dialog does not have a Properties # button - so an error is raised. # because we re-run the resolution from the start we find the new pagesetup dialog. app.PageSetup.Properties.Click() ``` -------------------------------- ### GetCheckState() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the checked state of a button control. ```APIDOC ## GetCheckState() ### Description Gets the checked state of a button control. ### Method (pywinauto.controls.win32_controls.ButtonWrapper method) ``` -------------------------------- ### GetBase() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the base value of an up-down control. ```APIDOC ## GetBase() ### Description Gets the base value of an up-down control. ### Method (pywinauto.controls.common_controls.UpDownWrapper method) ``` -------------------------------- ### Connect to Existing Application Source: https://pywinauto.readthedocs.io/en/latest/HISTORY.html Connect to an already running application by its title. This method is used to interact with existing windows. ```python app = Application().connect_(title = 'Find') app.Find.Close.Click() app.NotePad.MenuSelect("File->Exit") ``` -------------------------------- ### Application Methods Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Methods available on the pywinauto Application class. ```APIDOC ## Application Methods ### Description Methods provided by the `pywinauto.application.Application` class. ### Methods - `is64bit()` (pywinauto.application.Application method) - `is_process_running()` (pywinauto.application.Application method) ``` -------------------------------- ### get_view() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the view associated with a calendar control. ```APIDOC ## get_view() ### Description Gets the view associated with a calendar control. ### Method (pywinauto.controls.common_controls.CalendarWrapper method) ``` -------------------------------- ### pywinauto.backend.register Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.backend.html Registers a new backend with the system, providing its name and associated base classes. ```APIDOC ## register(name, element_info_class, generic_wrapper_class) ### Description Register a new backend. ### Parameters #### Path Parameters - **name** (string) - Required - The name for the new backend. - **element_info_class** (class) - Required - The ElementInfo base class for this backend. - **generic_wrapper_class** (class) - Required - The BaseWrapper base class for this backend. ``` -------------------------------- ### get_toggle_state() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the toggle state of a button control. ```APIDOC ## get_toggle_state() ### Description Gets the toggle state of a button control. ### Method (pywinauto.controls.uia_controls.ButtonWrapper method) ``` -------------------------------- ### get_today() Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the current date from a calendar control. ```APIDOC ## get_today() ### Description Gets the current date from a calendar control. ### Method (pywinauto.controls.common_controls.CalendarWrapper method) ``` -------------------------------- ### Accessing Dialogs and Controls Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait Demonstrates different ways to access dialogs and controls within an application instance using attribute access, dictionary-like lookup, or the child_window method. ```python dlg = app.YourDialogTitle dlg = app.child_window(title="your title", classname="your class", ...) dlg = app['Your Dialog Title'] ``` ```python ctrl = dlg.YourControlTitle ctrl = dlg.child_window(title="Your control", classname="Button", ...) ctrl = dlg["Your control"] ``` -------------------------------- ### Connect to a Running Application by Process ID Source: https://pywinauto.readthedocs.io/en/latest/HowTo.html Use the `connect` method with the `process` parameter to attach to an already running application using its process ID. ```python app = Application().connect(process=2341) ``` -------------------------------- ### get_show_state Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the visibility state of a window or control. ```APIDOC ## get_show_state() ### Description Retrieves the visibility state (e.g., shown, hidden, minimized, maximized) of a window or control. ### Method N/A (Method of HwndWrapper, UIAWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **str**: The visibility state. ``` -------------------------------- ### get_selected_tab Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the currently selected tab in a TabControl. ```APIDOC ## get_selected_tab() ### Description Retrieves the currently active tab in a TabControl. ### Method N/A (Method of TabControlWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **int**: The index of the selected tab. ``` -------------------------------- ### os_arch Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.sysinfo.html Returns the architecture of the operating system. ```APIDOC ## os_arch() ### Description Returns the architecture of the operating system. ### Method N/A (Function Call) ### Endpoint N/A (Function Call) ### Parameters None ### Response Returns a string representing the OS architecture (e.g., 'x86' or 'x64'). ``` -------------------------------- ### get_part_text Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the text of a part in a StatusBar control. ```APIDOC ## get_part_text() ### Description Retrieves the text content of a specific part within a StatusBar control. ### Method N/A (Method of StatusBarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **str**: The text of the status bar part. ``` -------------------------------- ### Ansible Playbook for Remote GUI Automation Source: https://pywinauto.readthedocs.io/en/latest/remote_execution.html This Ansible playbook demonstrates how to run GUI automation scripts on remote hosts using the win_psexec module. It requires specifying the command, PsExec executable path, and connection details. ```yaml --- - name: test ra module hosts: ***** tasks: - name: run GUI automation win_psexec: command: python pywinauto_example.py executable: C:\Windows\PSTools\psexec.exe interactive: yes username: admin password: ****** hostnames: ****** ``` -------------------------------- ### Minimize Window using Wrapper Object vs Direct Call Source: https://pywinauto.readthedocs.io/en/latest/getting_started.html Demonstrates two ways to minimize a window: directly calling the minimize method on the window specification (production code) and calling it via the wrapper object (debugging). ```python dlg_spec.wrapper_object().minimize() # while debugging dlg_spec.minimize() # in production ``` -------------------------------- ### get_part_rect Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the rectangle of a part in a StatusBar control. ```APIDOC ## get_part_rect() ### Description Retrieves the rectangular area of a specific part within a StatusBar control. ### Method N/A (Method of StatusBarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **RECT**: The rectangle of the status bar part. ``` -------------------------------- ### Example Usage of wait_until_passes Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.timings.html?highlight=wait_until_passes Demonstrates how to use wait_until_passes to wait for a window to exist within a specified timeout and retry interval. It includes error handling for TimeoutError. ```python try: # wait a maximum of 10.5 seconds for the # window to be found in increments of .5 of a second. # P.int a message and re-raise the original exception if never found. wait_until_passes(10.5, .5, self.Exists, (ElementNotFoundError)) except TimeoutError as e: print("timed out") raise e. ``` -------------------------------- ### get_page_size Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the page size of a Trackbar control. ```APIDOC ## get_page_size() ### Description Retrieves the page size (increment when page up/down is pressed) of a Trackbar control. ### Method N/A (Method of TrackbarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **int**: The page size. ``` -------------------------------- ### pywinauto.application.process_from_module Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait_not Returns the running process associated with a given module path. ```APIDOC ## pywinauto.application.process_from_module ### Description Return the running process with path module. ### Parameters #### Path Parameters - **module** (str) - Required - The path of the module. ``` -------------------------------- ### get_num_ticks Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the number of ticks on a Trackbar control. ```APIDOC ## get_num_ticks() ### Description Retrieves the total number of tick marks on a Trackbar control. ### Method N/A (Method of TrackbarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **int**: The number of ticks. ``` -------------------------------- ### get_month_range Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the month range for a Calendar control. ```APIDOC ## get_month_range() ### Description Retrieves the valid month range for a Calendar control. ### Method N/A (Method of CalendarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **tuple**: A tuple containing the minimum and maximum month. ``` -------------------------------- ### Exceptions Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html?highlight=wait_not The pywinauto.application module defines specific exceptions for handling application-related errors, such as connection failures or startup problems. ```APIDOC _exception_pywinauto.application.AppNotConnected Bases: Exception Application has not been connected to a process yet. _exception_pywinauto.application.AppStartError Bases: Exception There was a problem starting the Application. _exception_pywinauto.application.ProcessNotFoundError Bases: Exception Could not find that process. ``` -------------------------------- ### exstyle Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.handleprops.html Return the extended style of the window. ```APIDOC ## exstyle ### Description Return the extended style of the window. ### Parameters * **handle** - The window handle. ### Returns The extended style of the window. ``` -------------------------------- ### get_month_delta Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the month delta for a Calendar control. ```APIDOC ## get_month_delta() ### Description Retrieves the month delta (difference from current month) for a Calendar control. ### Method N/A (Method of CalendarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **int**: The month delta. ``` -------------------------------- ### exstyle Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.controls.hwndwrapper.html?highlight=draw_outline Returns the Extended style of the window. ```APIDOC ## exstyle ### Description Returns the Extended style of window. Return value is a long. Combination of WS_* and specific control specific styles. See HwndWrapper.has_style() to easily check if the window has a particular style. ### Method N/A (This is a property getter) ### Endpoint N/A ``` -------------------------------- ### get_menu_path Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the menu path for a Menu item. ```APIDOC ## get_menu_path() ### Description Retrieves the full path of a menu item. ### Method N/A (Method of Menu, MenuItem) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **str**: The menu path. ``` -------------------------------- ### get_line_size Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets the line size of a Trackbar control. ```APIDOC ## get_line_size() ### Description Retrieves the line size (increment) of a Trackbar control. ### Method N/A (Method of TrackbarWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **int**: The line size. ``` -------------------------------- ### dumpwindow Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.handleprops.html Dump a window to a set of properties. ```APIDOC ## dumpwindow ### Description Dump a window to a set of properties. ### Parameters * **handle** - The window handle. ### Returns A set of properties for the window. ``` -------------------------------- ### get_line Source: https://pywinauto.readthedocs.io/en/latest/genindex.html Gets a line of text from an Edit control. ```APIDOC ## get_line() ### Description Retrieves a specific line of text from an Edit control. ### Method N/A (Method of EditWrapper) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response - **str**: The line of text. ``` -------------------------------- ### Register New Backend in pywinauto Source: https://pywinauto.readthedocs.io/en/latest/HISTORY.html To implement support for new platforms, register a new backend using this function. The minimal set for a new backend includes its name and two classes inherited from ElementInfo and BaseWrapper. ```python pywinauto.backend.register() ``` -------------------------------- ### timings.Timings.fast() Source: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.timings.html Sets all timing values to fast presets. Timeouts are set to 1 second, waits to 0 seconds, and retries to a minimum of 0.001 seconds. Existing faster times are preserved. ```APIDOC ## timings.Timings.fast() ### Description Sets fast timing values. Timeouts are set to 1 second, waits to 0 seconds, and retries to 0.001 seconds (minimum). Existing faster times are preserved. ### Method Call ### Parameters None ### Response None ```