我試圖使用comtypes包使用方法在Python IUIAutomation::ElementFromPoint。有很多例子說明如何在C++中使用它,但不在Python中使用它。這個簡單的代碼重新在64位Windows 10中的問題(Python 2.7版32位):如何在Python中將POINT結構傳遞給ElementFromPoint方法?
import comtypes.client
UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
UIA_dll.IUIAutomation().ElementFromPoint(10, 10)
我得到以下錯誤:
TypeError: Expected a COM this pointer as first argument
創建POINT
結構這種方式並不能幫助還有:
from ctypes import Structure, c_long
class POINT(Structure):
_pack_ = 4
_fields_ = [
('x', c_long),
('y', c_long),
]
point = POINT(10, 10)
UIA_dll.IUIAutomation().ElementFromPoint(point) # raises the same exception
謝謝,西蒙!這正是我需要的。 –