Python-UIAutomation-for-Windows: automate Windows desktop apps with Python
🐍Python 3 wrapper of Microsoft UIAutomation. Support UIAutomation for MFC, WindowsForm, WPF, Modern UI(Metro UI), Qt, IE, Firefox, Chrome ...
At a glance
- What is it?
- uiautomation is a Python 3 library that wraps Microsoft's UIAutomation API, enabling scripts to control desktop applications by traversing the accessibility control tree. It works with MFC, Windows Forms, WPF, Chrome, and Electron apps on Windows.
- Who is it for?
- uiautomation is appropriate for Windows developers who need to automate desktop applications that expose an UIAutomation provider, including MFC, WPF, Windows Forms, Chrome, and Electron apps. It is not appropriate on Linux or macOS, as the README states Windows-only support.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 121 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 1, 2026, and from our analysis. They are not legal advice.
Editorial analysis
What uiautomation does and what it wraps
Microsoft UIAutomation is a Windows accessibility API that exposes information about the controls in a running application to external clients. Applications that implement an UIAutomation Provider, such as those built with WPF, MFC, Windows Forms, or Qt, publish a control tree that UIAutomation clients can read and interact with. uiautomation is a Python 3 library that bridges this API, letting Python scripts find controls by their properties, read their state, and send input such as keystrokes, mouse clicks, and pattern invocations.
The README states the project is developed in the author's spare time for personal use and is shared under the Apache License 2.0. The library targets Windows XP with SP3 through Windows 11. The minimum server-side platform is Windows Server 2003 with SP2.
A separate C++ DLL, UIAutomationClient, is referenced in the README as the source component for the native bindings that uiautomation depends on.
How the control tree and searchDepth work
UIAutomation exposes every visible UI element in a tree structure. The root of the tree is the desktop (referred to as PaneControl with Name='Desktop' and Depth=0). Top-level windows are at depth 1. Each window's controls are nested below it at increasing depths.
uiautomation searches the tree starting from a specified node and stopping at a specified search depth. The README gives a concrete example to illustrate why depth matters for performance. Searching from the root with searchDepth=3 forces uiautomation to traverse over 200 controls before finding the target EditControl:
uiautomation.EditControl(searchDepth=3, Name='myedit2').SendKeys('hi')A faster approach traverses to an intermediate parent first, then searches within it at a shallow depth:
window2 = uiautomation.WindowControl(searchDepth=1, Name='window2') # search 2 times
sub = window2.Control(searchDepth=1, Name='2-4') # search 4 times
edit = sub.EditControl(searchDepth=1, Name='myedit2') # search 2 times
edit.SendKeys('hi')The README shows the same logic as a single chained call, indicating both patterns produce equivalent results. The depth-aware approach is important for performance in applications with deep or wide control hierarchies.
Installing uiautomation and using the automation.py script
Install the library via pip:
pip install uiautomationAfter installation, a script named automation.py is placed in the Python Scripts directory (C:\PythonXX\Scripts\automation.py). This script traverses the UI controls of any running application and prints them to the terminal and to a log file named @AutomationLog.txt.
The README gives several example invocations: - automation.py -t 0 -n prints the active window's full control tree with full names - automation.py -r -d 1 -t 0 prints the desktop root and its top-level child windows - automation.py -t 3 starts a 3-second countdown before capturing the control tree, giving time to switch to the target window
For each control, automation.py prints the ControlType, ClassName, Name, and Depth, and lists the UIAutomation patterns the control supports. Patterns determine which interactions are valid for a control: an EditControl with the ValuePattern can have its text set programmatically, while a control with the InvokePattern can be clicked.
Automating an application: the Notepad example
The README provides a worked example that automates Windows Notepad. The script launches Notepad, finds its window in the control tree using searchDepth=1 and the Notepad class name, locates the edit area, types text, and uses the application's menus to save the file. The README also states the script generates a GIF animation demonstrating the automation in action. A demos/ directory in the repository contains automation_calculator.py as a further simple demonstration.
A key detail from the README: the standard Win32 Notepad is required. The Windows 11 version of Notepad from the Microsoft Store uses a different control hierarchy and is not compatible with this approach. The README explicitly states to uninstall the Store version if needed.
The README also shows how automation.py -t 3 with focus switched to Notepad produces output including the ControlType hierarchy from the desktop root through the WindowControl, EditControl, ScrollBarControl, and TitleBar buttons, each at their respective depth levels. This output is saved to @AutomationLog.txt for review.
Application type coverage and known limitations
The README lists application types that uiautomation supports: MFC, Windows Forms, WPF, Modern UI (Metro UI), Qt (with the caveat 'partly'), Firefox (versions 56 and below or 60 and above), Chrome, and Electron apps. Electron apps require launching Chrome with the --force-renderer-accessibility command-line parameter to expose UIAutomation data.
The Qt support is explicitly qualified as partial. The README does not detail which Qt control types work and which do not.
Metro UI applications on Windows 8 and 8.1 require the app to remain in the foreground. If a Metro app is moved to the background, uiautomation cannot access its controls.
The README notes that Python 3.7.6 and 3.8.1 have a known incompatibility with comtypes (the COM interface library uiautomation depends on) and should not be used. The README links to the upstream comtypes issue for details.
Running Python as administrator is recommended. Without administrator privileges, uiautomation may fail to enumerate controls or read their properties on Windows 7 and later. For automated testing in a CI environment, this administrator requirement adds setup overhead.
The last push to the repository was on 2026-06-02.
How uiautomation compares to pywinauto
pywinauto is a Windows GUI automation library that also targets desktop applications. Both uiautomation and pywinauto work on Windows only and support similar application types. The key difference is the underlying API layer.
uiautomation wraps the Microsoft UIAutomation framework, which is an accessibility API built into Windows. It is the same API that screen readers and accessibility tools use, which means it works with any application that implements an UIAutomation Provider, including newer WPF and UWP applications.
pywinauto supports both the older Win32 API backend and the UIAutomation backend. The Win32 backend works for older applications that do not expose UIAutomation providers. For applications that do expose UIAutomation, pywinauto routes through the same underlying API that uiautomation uses directly. The practical difference is that pywinauto offers a higher-level abstraction layer and supports both backends through a single interface, while uiautomation is a thinner, more direct wrapper of the UIAutomation API with an explicit control tree navigation model.
One further distinction: uiautomation ships with the automation.py inspection script that works standalone without writing any code, making it useful for exploring an application's control tree before writing automation logic. pywinauto provides a similar inspection capability through its own tools but as part of the library's API rather than a standalone script.
Editorial conclusion
uiautomation is appropriate for Windows developers who need to automate desktop applications that expose an UIAutomation provider, including MFC, WPF, Windows Forms, Chrome, and Electron apps. It is not appropriate on Linux or macOS, as the README states Windows-only support. Avoid Python versions 3.7.6 and 3.8.1, which have a known comtypes incompatibility documented in the README. Running Python as administrator is recommended, as the README notes that without it, uiautomation may fail to enumerate controls on Windows 7 and later.
Frequently asked questions
What is Microsoft UIAutomation?
Microsoft UIAutomation is a Windows accessibility API that exposes the controls of a running application as a hierarchical tree. Applications built with WPF, MFC, Windows Forms, or other frameworks implement UIAutomation Providers that publish this tree. Client programs, such as screen readers and the uiautomation Python library, use it to read control state and send input.
Which Python versions should not be used with uiautomation?
The README explicitly states not to use Python 3.7.6 and 3.8.1 because comtypes, a dependency of uiautomation, does not work correctly in those two releases. The README links to the upstream comtypes issue. Any earlier or later Python 3 release is safe.
Do I need to run Python as administrator to use uiautomation?
The README recommends running Python as administrator. Without administrator privileges, uiautomation may fail to enumerate controls or read their properties on Windows 7 and later systems. Automation scripts that run without elevation may silently find zero controls for applications they cannot access.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/yinkaisheng-python-uiautomation-for-windows)