【发布时间】:2020-11-04 08:38:55
【问题描述】:
目标:我想检索 UI 元素的以下属性:名称、类、控件类型和父名称。该元素可能属于在 Internet Explorer 上打开的 Outlook 或 Web 应用程序。
Python 解释器: 3.7
Python 库: Comtypes
研究:
OUTLOOK: 为了在 Microsoft Outlook 中检索特定元素的属性,我使用 comtypes 创建 UIautomationCore.dll 的对象。我可以根据特定元素的点来检索名称和类,但我找不到检索控件类型的方法,另一方面是具有该点的父元素名称。我在 Microsoft UI 自动化中发现我必须使用 TreeWalker 才能获取有关父元素的信息。但是,我不知道如何在 Python 中实现。
WEB 应用程序(Internet Explorer):我使用的是同一个库,我可以检索位于 Internet Explorer 浏览器中的元素。但是,当我无法获取位于 Web 应用程序(正文)内容中的一个按钮的这些属性时。
问题:如何通过 Microsoft UI 自动化检索 Outlook 中的控件类型和父元素名称?以及在使用 Internet Explorer 时如何检索这些属性?
我当前的代码:
import comtypes
from comtypes.client import *
comtypes.client.GetModule('UIAutomationCore.dll')
from comtypes.gen.UIAutomationClient import *
# get IUIAutomation interface
uia = CreateObject(CUIAutomation._reg_clsid_, interface=IUIAutomation)
# import tagPOINT from wintypes
from ctypes.wintypes import tagPOINT
point = tagPOINT(1833, 95)
element = uia.ElementFromPoint(point)
walker = ViewWalker
parentElement = walker.GetParent(element)
name=element.currentName
parentName = parentElement.currentName
print("elementName:", name)
print("parentElementName: ", parentName)
赞成:有人可以就如何用 Python 实现 IUIAutomationElement COM 接口给出一些指导吗?任何链接或书籍都可能对理解它非常有用。
【问题讨论】:
标签: python microsoft-ui-automation comtypes