{"id":22510,"library":"uiautomation","title":"uiautomation","description":"Python library for Windows UI Automation, enabling control of desktop applications via Microsoft UI Automation API. Current version 2.0.29, active development with occasional releases.","status":"active","version":"2.0.29","language":"python","source_language":"en","source_url":"https://github.com/yinkaisheng/Python-UIAutomation-for-Windows","tags":["windows","uia","automation","gui-testing"],"install":[{"cmd":"pip install uiautomation","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Required for COM interop with UIA","package":"comtypes","optional":false}],"imports":[{"note":"Wildcard import pollutes namespace; use alias 'auto' for brevity","wrong":"from uiautomation import *","symbol":"uiautomation","correct":"import uiautomation as auto"},{"note":"","wrong":"","symbol":"WindowControl","correct":"from uiautomation import WindowControl"}],"quickstart":{"code":"import uiautomation as auto\n\n# Launch Notepad if not running\nif not auto.WindowControl(searchDepth=1, Name='Untitled - Notepad').Exists(0,0):\n    os.system('notepad')\n    time.sleep(1)\n\nwindow = auto.WindowControl(searchDepth=1, Name='Untitled - Notepad')\nedit = window.EditControl()\nedit.Click()\nedit.SendKeys('Hello, UI Automation!')\nprint('Text sent.')\nwindow.GetWindowPattern().Close()","lang":"python","description":"Finds Notepad window, sends text, and closes it."},"warnings":[{"fix":"Use Python 3.11 or lower, or monitor GitHub issues for compatibility fixes.","message":"Python 3.12+ may break due to changes in ctypes and COM. Tested up to 3.11.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always specify searchDepth (e.g., 1 for top-level windows) or use Control(searchFromControl=root).","message":"Controls are found with 'searchDepth' or 'searchFromRoot=False'. Default searchDepth is 0 (immediate children) which often finds nothing.","severity":"gotcha","affected_versions":"all"},{"fix":"Run script as administrator or use SetFocus before SendKeys.","message":"SendKeys may not work on elevated (admin) apps if script is not elevated.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use 'from uiautomation import WindowControl' or 'auto.WindowControl'.","cause":"Old import pattern; Control is not directly exported, use WindowControl etc.","error":"ImportError: cannot import name 'Control' from 'uiautomation'"},{"fix":"Upgrade: pip install --upgrade uiautomation","cause":"Outdated version (<1.0) or incorrect installation.","error":"AttributeError: module 'uiautomation' has no attribute 'WindowControl'"},{"fix":"Call 'auto.CoInitializeEx(0)' at start of script.","cause":"COM not initialized in current thread.","error":"comtypes.COMError: (-2147221008, 'CoInitialize has not been called.', ...)"},{"fix":"Increase searchDepth or use Control(searchFromControl=desktop). Example: auto.GetRootControl()","cause":"Search criteria too strict or wrong searchDepth.","error":"uiautomation.controls.ControlNotFoundException: Cannot find control"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}