Of course! The term "Python IAccessible" refers to using Python to interact with the Microsoft Active Accessibility (MSAA) framework, specifically through its COM interface called IAccessible.

This is a powerful technique for UI Automation on Windows. It allows you to programmatically inspect and control the user interface of other applications, just like a screen reader or a testing tool would.
Here's a comprehensive guide covering what it is, why you'd use it, how to do it, and the modern alternatives.
What is IAccessible?
- IAccessible is a Component Object Model (COM) interface developed by Microsoft.
- It's the core technology behind Microsoft Active Accessibility (MSAA), an accessibility framework.
- Its purpose is to provide a standardized way for applications to expose their UI elements (like buttons, text fields, lists) to assistive technologies (ATs) such as screen readers (JAWS, NVDA) and on-screen keyboards.
- Each UI element exposes information through the
IAccessibleinterface, including:- Its role (e.g., "button", "text", "list item").
- Its name (e.g., "OK", "Username").
- Its state (e.g., "focused", "disabled", "checked").
- Its location and size.
- Relationships to other elements (e.g., its parent, children).
Why Use Python with IAccessible?
You would use Python to interact with IAccessible for tasks like:
- Automated UI Testing: Automate testing of a Windows GUI application by simulating user actions (clicking, typing) and verifying the state of UI elements.
- Data Scraping: Extract information from a desktop application that doesn't have a simple API or command-line interface (e.g., an old legacy application).
- Custom Accessibility Tools: Build a custom script or tool that interacts with an application in a specific way for a user with disabilities.
- Monitoring UI Changes: Watch for changes in an application's UI and react to them.
How to Use IAccessible in Python: The pywin32 Library
The most common and direct way to use IAccessible in Python is by using the pywin32 library, which provides Python access to many Windows APIs, including COM.

Step 1: Installation
First, you need to install pywin32. Open your command prompt or terminal and run:
pip install pywin32
Step 2: Basic Concepts
- Get a COM Pointer to
IAccessible: You first need to get a reference to theIAccessibleobject for the window or element you're interested in. This is often done by finding the window handle (HWND) first. - Use the
pyIAccessibleHelper:pywin32includes a helper module,win32com.axcontrol.axscript, which has aGetIAccessibleFromHWNDfunction. This is the easiest way to get the top-levelIAccessibleobject for a window. - Navigate the Tree: The
IAccessibleobject acts like a tree. You can navigate to its children to find more specific elements. - Call Methods and Get Properties: You can call methods (like
DoAction) and get properties (likeaccName,accRole) on theIAccessibleobject.
Step 3: Practical Examples
Let's build a simple script that gets information from the Windows Calculator.
Example 1: Getting the Name and Role of the Calculator's Main Window
This script will find the Calculator window and print its name and role.
import win32gui
import win32com.axcontrol.axscript as axscript
def get_accessible_info(hwnd):
"""Gets the top-level IAccessible object for a given window handle."""
try:
# Get the IAccessible object for the window
acc_obj = axscript.GetIAccessibleFromHWND(hwnd)
return acc_obj
except Exception as e:
print(f"Could not get IAccessible for HWND {hwnd}: {e}")
return None
def main():
# Find the Calculator window by its class name
# You can find class names using tools like Spy++ or AutoIt Window Info
hwnd = win32gui.FindWindow("Windows.UI.Core.CoreWindow", "Calculator")
if hwnd:
print(f"Found Calculator HWND: {hwnd}")
acc = get_accessible_info(hwnd)
if acc:
# Get the name of the accessible object
# accName takes a child ID. 0 means the object itself.
name = acc.accName(0)
# Get the role of the accessible object
role = acc.accRole(0)
print(f"App Name: {name}")
print(f"App Role: {role}") # Typically ROLE_APP_APPLICATION (0x1a)
# Let's try to get the display's IAccessible, which is a child
# of the main app window.
display_acc = acc.accChild(0)
if display_acc:
# accChild can return an IAccessible object or a simple integer child ID.
# We need to check the type.
if hasattr(display_acc, 'accName'):
display_name = display_acc.accName(0)
display_value = display_acc.accValue(0)
print(f"\nDisplay Child Name: {display_name}")
print(f"Display Child Value: {display_value}")
else:
print("Calculator window not found. Please open it.")
if __name__ == "__main__":
main()
To run this:

- Open the Windows Calculator app.
- Run the Python script.
You should see output similar to this:
Found Calculator HWND: 12345678 # Your actual HWND will be different
App Name: Calculator
App Role: 26 # The numeric value for ROLE_APP_APPLICATION
Display Child Name: Display is ready
Display Child Value: 0
Example 2: Finding and Clicking a Button (e.g., "5")
This is more complex and requires navigating the UI tree to find the specific button.
import win32gui
import win32com.client
import win32con
import time
def find_child_by_name(acc, target_name):
"""
Recursively searches the IAccessible tree for a child with a specific name.
Returns the IAccessible object of the first match.
"""
# Check the current object
try:
if acc.accName(0) == target_name:
return acc
except Exception:
pass
# Check children
child_count = acc.accChildCount
if child_count > 0:
for i in range(child_count):
child_id = i
# accChild can return an IAccessible object or an integer ID
child_obj = acc.accChild(child_id)
if isinstance(child_obj, int):
# If it's an integer, it's a simple element ID.
# We need to get its IAccessible parent, which is 'acc'.
# This is a simplification; a robust solution would need to handle this case better.
# For many UIs, child elements are full IAccessible objects.
continue
else:
# It's an IAccessible object, recurse
result = find_child_by_name(child_obj, target_name)
if result:
return result
return None
def click_button(acc, button_name):
"""Finds a button by its name and clicks it."""
button_acc = find_child_by_name(acc, button_name)
if button_acc:
print(f"Found button: '{button_name}'")
# The DoAction method is used to invoke an action (like a click)
# The action ID is usually 0 for the default action.
button_acc.accDoDefaultAction(0)
return True
else:
print(f"Could not find button: '{button_name}'")
return False
def main():
# Find the Calculator window
hwnd = win32gui.FindWindow("Windows.UI.Core.CoreWindow", "Calculator")
if not hwnd:
print("Calculator not found. Please open it.")
return
# Get the IAccessible object for the main window
ax_script = win32com.client.Dispatch("AxScript.AxScript")
acc = ax_script.GetIAccessibleFromHWND(hwnd)
if not acc:
print("Could not get IAccessible object.")
return
# Click the '5' button
click_button(acc, "Five")
time.sleep(1) # Wait for UI to update
# Click the '+' button
click_button(acc, "Plus")
time.sleep(1)
# Click the '3' button
click_button(acc, "Three")
time.sleep(1)
# Click the '=' button
click_button(acc, "Equals")
print("Automation finished. Check the calculator.")
if __name__ == "__main__":
main()
The Modern Alternative: UI Automation (UIA)
While IAccessible/MSAA is powerful, it's an older technology. Microsoft has since developed a more modern and robust framework called UI Automation (UIA).
Key Differences:
| Feature | IAccessible (MSAA) | UI Automation (UIA) |
|---|---|---|
| Technology | COM-based | .NET-based (with a COM interop layer) |
| Granularity | Less granular. Good for high-level elements. | More granular. Can access properties like font color, background, etc. |
| Performance | Can be slower. | Generally faster and more efficient. |
| Eventing | Basic event support. | Rich, event-driven model for real-time notifications. |
| Future | Largely superseded by UIA. | The current, recommended standard for Windows automation. |
Using UIA with Python
You can use UIA in Python via the pywin32 library as well, but it's more complex. A more popular and user-friendly approach is to use a wrapper library like uiautomation.
Installation:
pip install uiautomation
Example: Clicking the "5" button in Calculator using uiautomation
Notice how much cleaner and more intuitive this is.
import uiautomation as auto
import time
def main():
# Find the Calculator window by its name
# The second argument is the search depth
calculator = auto.WindowControl(Name="Calculator")
if not calculator.Exists(3): # Wait up to 3 seconds for it to appear
print("Calculator window not found.")
return
print("Found Calculator window.")
# Find the '5' button by searching within the calculator window
# We can use a more specific search path
# The button is inside a Pane, which is inside another Pane
five_button = calculator.PaneControl(PaneName="Number pad").ButtonControl(Name="Five")
if five_button.Exists(1):
print("Found 'Five' button. Clicking it.")
five_button.Click()
else:
print("Could not find 'Five' button.")
# Let's do a more complex sequence
time.sleep(0.5)
calculator.ButtonControl(Name="Seven").Click()
time.sleep(0.5)
calculator.ButtonControl(Name="Multiply").Click()
time.sleep(0.5)
calculator.ButtonControl(Name="Two").Click()
time.sleep(0.5)
calculator.ButtonControl(Name="Equals").Click()
print("Automation finished.")
if __name__ == "__main__":
main()
Summary: Which One Should You Use?
| Use Case | Recommended Technology | Why? |
|---|---|---|
| Modern Windows Apps (Win10/11) | UI Automation (uiautomation) |
It's the modern standard, more powerful, easier to use, and more reliable. |
| Older Desktop Apps (Win32, .NET Framework 2.0-3.5) | IAccessible (pywin32) |
Older apps may not support UIA or have better support for MSAA. |
| Legacy System Automation | IAccessible (pywin32) |
If you're stuck with very old software, this might be your only option. |
| Cross-Platform Automation | Not IAccessible | Look into libraries like PyAutoGUI (which uses image recognition) or Playwright (which can automate web browsers and some native apps via their WebDriver). |
Conclusion:
For any new project on Windows, start with UI Automation using the uiautomation library. It is vastly superior to the older IAccessible approach in terms of ease of use, power, and reliability.
Use the pywin32 and IAccessible approach only when you absolutely need to interact with applications that do not support UIA.
