Goal: I want to retrieve the following attributes of a UI element: Name, Class, Control type and parent name. The element could belong to Outlook or web application which is opened on Internet explorer.
Python interpreter: 3.7
Python library: Comtypes
Research made:
OUTLOOK: In order to retrieve the attributes of a particular element in Microsoft Outlook, I am using comtypes to create an object of UIautomationCore.dll. I could retrieve the name and class based on the point of a particular element, but I cannot find a way to retrieve the control type and on the other hand the parent element name having this point. I found in the Microsoft UI Automation that I must use the TreeWalker in order to get the information about the parent element. However, I do not know how to implement in Python.
WEB APPLICATION (Internet explorer): I am using the same library and I can retrieve the elements which are located in the Internet Explorer browser. However, when I cannot get these attributes of one button which are located in the content of the web application (body).
Question: How to retrieve the control type and parent element name in Outlook with Microsoft UI automation? and How to retrieve those attributes when I am working with Internet Explorer?.
My current code:
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)
Favor: Could someone give some guidelines on how to implement IUIAutomationElement COM interface with Python?. Any link or book could be very useful to understand it.