Msaa stands for Microsoft Active accessibility. This is similar to DCOM technology. The technical model is like this, UIProgramYou can expose an interface to allow another program to control it. The original intention of msaa technology is to facilitate the use of Windows programs for the disabled. For example, a blind person cannot see a window, but a blind person can connect to a computer through a USB reading screen, and the reading screen can obtain program information through the interface exposed by the UI program, transmitted to the blind in Braille or other forms.
Msaa provides such convenient functions that can naturally be used for UI automated testing. The interface exposed by msaa is called iaccessible.
To obtain the iaccessible interface in Python, follow these steps:
From Ctypes Import Windll, oledll, winerror, byref, pointer
From Ctypes. wintypes Import Point
FromComtypesImportComerror
FromComtypes. AutomationImportVariant
FromComtypes. ClientImportGetmodule
# Create wrapper for the oleacc. DLL Type Library
getmodule ( " oleacc. DLL " )
# import the interface we need from the wrapper
from comtypes. gen. accessibility Import iaccessible
def accessibleobjectfrompoint (x, y ):
" return an accessible object and an index. see msdn for details. "
PACC = pointer (iaccessible) ()
var = variant ()
oledll. oleacc. accessibleobjectfrompoint (point (x, y), byref (PACC),
byref (VAR)
return pACC, VAR
DefAccessibleobjectfromwindow (hwnd ):
PTR=Pointer (iaccessible )()
Res=Oledll. oleacc. accessibleobjectfromwindow (
Hwnd, 0,
Byref (iaccessible. _ IID _), byref (PTR ))
ReturnPTR