zoukankan      html  css  js  c++  java
  • Python获取IAccessible接口

    MSAA的全称是Microsoft Active Accessibility。这是类似DCOM技术。技术模型是这样的,UI程序可以暴露出一个Interface,方便另一个程序对其进行控制。 MSAA技术的初衷是为了方便残疾人使用Windows 程序。比如盲人看不到窗口,但是盲人可以通过一个USB读屏器连接到电脑上, 读屏器通过UI程序暴露出来的这个Interface,就可以获取程序信息,通过盲文或者其它形式传递给盲人。

    MSAA提供了如此方便的功能, UI自动化测试自然可以借用这项技术。MSAA暴露出来的Interface叫做 IAccessible。

    Python中获取IAccessible接口的方法如下:

    from ctypes import windll, oledll, WinError, byref, POINTER
    from ctypes.wintypes import POINT

    from comtypes import COMError
    from comtypes.automation import VARIANT
    from comtypes.client import GetModule

    # 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

    def AccessibleObjectFromWindow(hwnd):
        ptr 
    = POINTER(IAccessible)()
        res 
    = oledll.oleacc.AccessibleObjectFromWindow(
          hwnd,0,
          byref(IAccessible._iid_),byref(ptr))
        
    return ptr


  • 相关阅读:
    SmartJS 第一期(0.1)发布
    smartJS 0.1 API 讲解
    smartJS 0.1 API 讲解
    20160113006 asp.net实现ftp上传代码(解决大文件上传问题)
    20151224001 GridView 多按钮的各种使用方法
    20151221001 GridView 模板
    20151218001 雕爷自白:我为什么非要这么干
    20151210001 DataGridView 选中与被选中
    20151126001 网页中嵌入谷歌动态地图
    20151125001 询问对话框 中的文字换行
  • 原文地址:https://www.cnblogs.com/coderzh/p/1752141.html
Copyright © 2011-2022 走看看