Python UIAutomation for Windows - comprehensive library for automating Windows applications using Microsoft's UIAutomation framework
npx @tessl/cli install tessl/pypi-uiautomation@1.1.0Python UIAutomation for Windows provides comprehensive automation capabilities for Windows applications using Microsoft's UIAutomation framework. It enables Python developers to interact with and control Windows applications built with various UI frameworks including MFC, Windows Forms, WPF, Modern UI, Qt (partial support), Firefox, and Chrome.
pip install uiautomationimport uiautomationAll public API is available through the main module import:
# Control classes are available directly
window = uiautomation.WindowControl()
button = uiautomation.ButtonControl()
# Global functions are available
root = uiautomation.GetRootControl()
focused = uiautomation.GetFocusedControl()import uiautomation
# Find and interact with a window
calculator = uiautomation.WindowControl(searchDepth=1, Name='Calculator')
# Find a button within the window and click it
button7 = calculator.ButtonControl(Name='Seven')
button7.Click()
# Type into an edit control
edit = calculator.EditControl(ClassName='Edit')
edit.SendKeys('123')
# Get control properties
print(f"Button name: {button7.Name}")
print(f"Button bounds: {button7.BoundingRectangle}")
print(f"Is enabled: {button7.IsEnabled}")
# Wait for controls to appear or disappear
uiautomation.WaitForExist(button7, timeout=5)UIAutomation is built around the Windows UI Automation framework and provides a Python interface with several key components:
The library follows a consistent API pattern where controls are located using named parameters matching their Windows properties, then manipulated through methods or patterns.
Core functionality for finding, accessing, and managing UI controls within the Windows control tree. Provides the foundation for all automation operations.
def GetRootControl() -> Control: ...
def GetFocusedControl() -> Control: ...
def GetForegroundControl() -> Control: ...
def ControlFromPoint(x: int, y: int) -> Control: ...
def ControlFromHandle(handle: int) -> Control: ...
def FindControl(root: Control, **kwargs) -> Control: ...Comprehensive set of 40+ control classes representing all Windows UI element types, from basic buttons and text fields to complex data grids and tree views.
class Control:
def Click(self) -> None: ...
def SendKeys(self, keys: str) -> None: ...
def SetFocus(self) -> None: ...
class WindowControl(Control): ...
class ButtonControl(Control): ...
class EditControl(Control): ...
class ListControl(Control): ...Mouse and keyboard input simulation for automating user interactions with applications. Supports clicking, typing, dragging, and special key combinations.
def Click(x: int, y: int) -> None: ...
def SendKey(key: int, modifiers: int = 0) -> None: ...
def SendKeys(keys: str) -> None: ...
def DragDrop(x1: int, y1: int, x2: int, y2: int) -> None: ...Implementation of Windows UI Automation patterns for specialized control operations like invoking buttons, setting values, handling selections, and managing scrollable content.
class InvokePattern:
def Invoke(self) -> None: ...
class ValuePattern:
def SetValue(self, value: str) -> None: ...
def GetValue(self) -> str: ...
class SelectionPattern:
def GetSelection(self) -> list: ...Bitmap operations for capturing screenshots of controls or screen areas, pixel color analysis, and image-based verification in automation scripts.
class Bitmap:
@staticmethod
def FromControl(control: Control) -> Bitmap: ...
def ToFile(self, filename: str) -> None: ...
def GetPixelColor(self, x: int, y: int) -> int: ...Comprehensive Windows API wrapper providing low-level system operations for window management, process control, and system utilities.
class Win32API:
@staticmethod
def SetForegroundWindow(handle: int) -> bool: ...
@staticmethod
def ShowWindow(handle: int, state: int) -> bool: ...
@staticmethod
def GetWindowText(handle: int) -> str: ...Comprehensive logging system with color support and control tree enumeration for debugging automation scripts and understanding application structure.
class Logger:
def WriteLine(self, text: str) -> None: ...
def ColorfulWriteLine(self, text: str, color: int) -> None: ...
def LogControl(control: Control) -> None: ...
def EnumAndLogControl(control: Control, depth: int) -> None: ...Common exceptions that may be raised:
RuntimeError: "Can not get an instance of IUIAutomation" - requires Windows update KB971513 for Windows XP--force-renderer-accessibility command line flag# Version Information
VERSION: str # Library version string (e.g., "1.1.15")
# Constants
OPERATION_WAIT_TIME: float # Default wait time after operations (0.5 seconds)
class Point:
def __init__(self, x: int, y: int): ...
x: int
y: int
class Rect:
def __init__(self, left: int, top: int, right: int, bottom: int): ...
left: int
top: int
right: int
bottom: int
class Control:
Name: str
ControlType: int
ClassName: str
AutomationId: str
ProcessId: int
IsEnabled: bool
HasKeyboardFocus: bool
IsKeyboardFocusable: bool
IsOffScreen: bool
BoundingRectangle: Rect
Handle: int