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


  • 相关阅读:
    JQ 鼠标滑过按钮改变背景图片
    TreeView 用法(有代码)
    MVC框架 IE浏览时IIS配置
    table 边框 不显示好td内为空串时,边框不显示
    DIV 内滚动条 样式的写法
    用 Grid 数据绑定
    架设支持Silverlight的Web服务器
    c# sql like @参数
    IE8 的margintop兼容问题
    弱符号与强符号
  • 原文地址:https://www.cnblogs.com/coderzh/p/1752141.html
Copyright © 2011-2022 走看看