我在屏幕上有鼠标位置,例如(10,10),并且我想将鼠标移到控件上。我该怎么办?
示例:
from pywinauto.application import Application
app = Application((backend="uia").start("notepad.exe")
dlg = app.top_window()
hardcoded_file_button_rec = dlg.File.rectangle() #<RECT L10, T10, R40, B40>
given_mouse_position = (10, 10)
found_file_button = search_by_position(app, given_mouse_position)
assert hardcoded_file_button_rec == found_file_button.rectangle()
pywinauto是否已经具有内置功能?在this question上,我发现了如何使用pywinauto遍历窗口中的所有控件。因此,对其进行迭代,我可以检查是否controls[i].rectancle().top == 10 and controls[i].rectancle().left == 10
。
正确的做法是什么?
答案 0 :(得分:1)
方法.from_point(x, y)
正在开发中。
解决方法在这里:issue #413。
以及StackOverflow上: How to pass POINT structure to ElementFromPoint method in Python?
清除任何元素的代码示例:
from ctypes.wintypes import tagPOINT
import pywinauto
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(x, y))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
wrapper = pywinauto.controls.uiawrapper.UIAWrapper(element)
wrapper
可能正是您需要的,因为它是具有.invoke()
等方法的可操作对象。