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


  • 相关阅读:
    SQL Server 性能优化之——T-SQL TVF和标量函数
    SQL Server 性能优化之——T-SQL 临时表、表变量、UNION
    Posix消息队列实现机制
    进程间通信基础知识整理
    进程间通信——FIFO(多个客户进程,一个服务进程)
    VMware+CentOS7+jdk1.7+hadoop2.4.1
    Java并发编程
    java并发编程
    读书笔记——Java IO
    读书笔记——异常
  • 原文地址:https://www.cnblogs.com/coderzh/p/1752141.html
Copyright © 2011-2022 走看看