CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-uiautomation

Python UIAutomation for Windows - comprehensive library for automating Windows applications using Microsoft's UIAutomation framework

Overview
Eval results
Files

control-types.mddocs/

Control Types

Comprehensive set of 40+ control classes representing all Windows UI element types. Each control class inherits from the base Control class and provides specialized functionality for specific UI elements like buttons, text fields, lists, and complex data grids.

Base Control Class

Control

The base class that all specific control types inherit from, providing common functionality for UI element interaction and property access.

class Control:
    """Base class for all UI controls."""
    
    # Core Properties
    Name: str                    # Display name of the control
    ControlType: int            # Windows control type identifier  
    ClassName: str              # Windows class name
    AutomationId: str           # Automation identifier
    ProcessId: int              # Process ID owning the control
    IsEnabled: bool             # Whether control accepts user input
    HasKeyboardFocus: bool      # Whether control currently has focus
    IsKeyboardFocusable: bool   # Whether control can receive focus
    IsOffScreen: bool           # Whether control is visible on screen
    BoundingRectangle: Rect     # Control bounds in screen coordinates
    Handle: int                 # Windows handle (HWND) if available
    
    def Click(self) -> None:
        """Click the control at its center point."""
    
    def RightClick(self) -> None:
        """Right-click the control at its center point."""
    
    def MiddleClick(self) -> None:
        """Middle-click the control at its center point."""
    
    def DoubleClick(self) -> None:
        """Double-click the control at its center point."""
    
    def MoveCursor(self) -> None:
        """Move the mouse cursor to the control's center."""
    
    def SetFocus(self) -> None:
        """Set keyboard focus to this control."""
    
    def SendKey(self, key: int, modifiers: int = 0) -> None:
        """
        Send a key to the control.
        
        Args:
            key: Virtual key code
            modifiers: Modifier keys (ALT, CTRL, SHIFT, WIN)
        """
    
    def SendKeys(self, keys: str) -> None:
        """
        Send a sequence of keys to the control.
        
        Args:
            keys: String representing keys to send
        """
    
    def WheelUp(self, times: int = 1) -> None:
        """Scroll mouse wheel up."""
    
    def WheelDown(self, times: int = 1) -> None:
        """Scroll mouse wheel down."""
    
    def GetChildren(self) -> list[Control]:
        """Get all direct child controls."""
    
    def GetParentControl(self) -> Control:
        """Get the parent control."""
    
    def GetTopLevelControl(self) -> Control:
        """Get the top-level window containing this control."""
    
    def GetNextSiblingControl(self) -> Control:
        """Get the next sibling control."""
    
    def GetPreviousSiblingControl(self) -> Control:
        """Get the previous sibling control."""
    
    def Exists(self, timeout: float = 0) -> bool:
        """Check if the control exists."""
    
    def WaitForExist(self, timeout: float = 15) -> bool:
        """Wait for the control to exist."""
    
    def WaitForDisappear(self, timeout: float = 15) -> bool:
        """Wait for the control to disappear."""
    
    def Show(self) -> None:
        """Show the control/window."""
    
    def Hide(self) -> None:
        """Hide the control/window."""
    
    def CaptureToImage(self, filename: str) -> None:
        """Capture the control to an image file."""
    
    def GetProperties(self) -> dict:
        """Get all control properties as a dictionary."""

Window and Container Controls

Controls that serve as containers for other UI elements or represent windows.

class WindowControl(Control):
    """Represents a top-level window."""

class PaneControl(Control):
    """Represents a pane container control."""

class GroupControl(Control):
    """Represents a group box control."""

class DocumentControl(Control):
    """Represents a document area control."""

class TitleBarControl(Control):
    """Represents a window title bar."""

class CustomControl(Control):
    """Represents a custom or unknown control type."""

Input Controls

Controls that accept user input through clicking, typing, or selection.

class ButtonControl(Control):
    """Represents a clickable button control."""

class EditControl(Control):
    """Represents a text input control."""

class CheckBoxControl(Control):
    """Represents a checkbox control."""

class RadioButtonControl(Control):
    """Represents a radio button control."""

class ComboBoxControl(Control):
    """Represents a combo box (dropdown) control."""

class SliderControl(Control):
    """Represents a slider control."""

class SpinnerControl(Control):
    """Represents a spinner (up/down) control."""

class SplitButtonControl(Control):
    """Represents a split button control."""

Display Controls

Controls that display information or provide visual feedback to users.

class TextControl(Control):
    """Represents a text display control."""

class ImageControl(Control):
    """Represents an image display control."""

class ProgressBarControl(Control):
    """Represents a progress bar control."""

class StatusBarControl(Control):
    """Represents a status bar control."""

class ToolTipControl(Control):
    """Represents a tooltip control."""

class SeparatorControl(Control):
    """Represents a separator line control."""

class ThumbControl(Control):
    """Represents a thumb control (e.g., slider thumb)."""

List and Tree Controls

Controls for displaying and selecting from collections of items.

class ListControl(Control):
    """Represents a list control."""

class ListItemControl(Control):
    """Represents an item within a list control."""

class TreeControl(Control):
    """Represents a tree view control."""

class TreeItemControl(Control):
    """Represents an item within a tree control."""

class DataGridControl(Control):
    """Represents a data grid control."""

class DataItemControl(Control):
    """Represents an item within a data grid."""

class TableControl(Control):
    """Represents a table control."""

Menu Controls

Controls for application menus and menu items.

class MenuControl(Control):
    """Represents a menu control."""

class MenuBarControl(Control):
    """Represents a menu bar control."""

class MenuItemControl(Control):
    """Represents a menu item control."""

Tab Controls

Controls for tabbed interfaces.

class TabControl(Control):
    """Represents a tab container control."""

class TabItemControl(Control):
    """Represents an individual tab within a tab control."""

Toolbar Controls

Controls for application toolbars.

class ToolBarControl(Control):
    """Represents a toolbar control."""

Scrolling Controls

Controls that provide scrolling functionality.

class ScrollBarControl(Control):
    """Represents a scroll bar control."""

Calendar Controls

Controls for date and time selection.

class CalendarControl(Control):
    """Represents a calendar control."""

Header Controls

Controls for column headers and header items.

class HeaderControl(Control):
    """Represents a header control."""

class HeaderItemControl(Control):
    """Represents an item within a header control."""

Hyperlink Controls

Controls for clickable hyperlinks.

class HyperlinkControl(Control):
    """Represents a hyperlink control."""

Modern UI Controls

Controls specific to Windows 8+ Modern UI applications.

class AppBarControl(Control):
    """Represents an app bar control (Windows 8+ Metro)."""

class SemanticZoomControl(Control):
    """Represents a semantic zoom control (Windows 8+ Metro)."""

Control Type Constants

class ControlType:
    """Constants for Windows UI Automation control types."""
    AppBarControl: int
    ButtonControl: int
    CalendarControl: int
    CheckBoxControl: int
    ComboBoxControl: int
    CustomControl: int
    DataGridControl: int
    DataItemControl: int
    DocumentControl: int
    EditControl: int
    GroupControl: int
    HeaderControl: int
    HeaderItemControl: int
    HyperlinkControl: int
    ImageControl: int
    ListControl: int
    ListItemControl: int
    MenuBarControl: int
    MenuControl: int
    MenuItemControl: int
    PaneControl: int
    ProgressBarControl: int
    RadioButtonControl: int
    ScrollBarControl: int
    SemanticZoomControl: int
    SeparatorControl: int
    SliderControl: int
    SpinnerControl: int
    SplitButtonControl: int
    StatusBarControl: int
    TabControl: int
    TabItemControl: int
    TableControl: int
    TextControl: int
    ThumbControl: int
    TitleBarControl: int
    ToolBarControl: int
    ToolTipControl: int
    TreeControl: int
    TreeItemControl: int
    WindowControl: int

Usage Examples

Basic Control Usage

import uiautomation

# Find and click a button
ok_button = uiautomation.ButtonControl(Name='OK')
if ok_button.Exists():
    ok_button.Click()

# Type into an edit control
username_field = uiautomation.EditControl(AutomationId='txtUsername')
username_field.SetFocus()
username_field.SendKeys('myusername')

# Check a checkbox
agree_checkbox = uiautomation.CheckBoxControl(Name='I agree to the terms')
agree_checkbox.Click()

Working with Lists and Trees

# Select an item from a list
file_list = uiautomation.ListControl(Name='Files')
file_item = file_list.ListItemControl(Name='document.txt')
file_item.Click()

# Expand a tree node
tree = uiautomation.TreeControl(Name='Directory Tree')
folder_node = tree.TreeItemControl(Name='My Documents')
folder_node.DoubleClick()  # Expand the folder

Menu Navigation

# Access application menu
menu_bar = uiautomation.MenuBarControl()
file_menu = menu_bar.MenuItemControl(Name='File')
file_menu.Click()

# Click a menu item
save_item = uiautomation.MenuItemControl(Name='Save')
save_item.Click()

Tab Navigation

# Switch to a different tab
tab_control = uiautomation.TabControl()
settings_tab = tab_control.TabItemControl(Name='Settings')
settings_tab.Click()

Complex Control Hierarchies

# Navigate through nested controls
main_window = uiautomation.WindowControl(Name='Application')
settings_pane = main_window.PaneControl(AutomationId='settingsPane')
user_group = settings_pane.GroupControl(Name='User Settings')
email_field = user_group.EditControl(Name='Email Address')
email_field.SendKeys('user@example.com')

Install with Tessl CLI

npx tessl i tessl/pypi-uiautomation

docs

automation-patterns.md

control-management.md

control-types.md

index.md

input-simulation.md

logging-debugging.md

screen-capture.md

windows-api.md

tile.json