【问题标题】:Get control by position on pywinauto通过 pywinauto 上的位置获取控制权
【发布时间】:2018-12-04 22:09:15
【问题描述】:

我在屏幕上有一个鼠标位置,例如 (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

什么是正确的做法?

【问题讨论】:

    标签: python python-3.x pywinauto


    【解决方案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() 等方法的可操作对象。

    【讨论】:

      猜你喜欢
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      • 2011-04-25
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-12
      相关资源
      最近更新 更多