首页 > 解决方案 > 使用 pywinauto 的检查工具中的数据

问题描述

我正在努力自动化一个名为 MEmu Instance Manager 的应用程序。

对于我的项目,我想使用 pywinauto 模块和 windows 工具包中的检查工具返回存在的实例数量以及它们的名称。

基于 Inspect 工具,逍遥应用的结构如下

MainWindow
    Parent
        Child1
        InstanceArea
            TARGET
            WIDGETS

当使用检查工具检查目标小部件时,这就是我得到的。

在此处输入图像描述

我要返回的字符串是“b__”

如何使用 python 返回Legacy|Accessible.Value字符串?在执行此操作之前是否需要指定小部件的路径?

如果是这样,怎么做?我已经阅读了很多关于 pywinauto 指南的有用信息,但是我无法在 MEmu 上应用我从检查中获得的信息。

例如,

在此处输入图像描述

使用上述信息,我无法通过提供的信息参考此窗口。

我是一个初学者,我已经为此工作了几天,但毫无进展。请帮助*哭泣

标签: python-3.xui-automationpywinautoinspect

解决方案


可能这种方式应该有效:

from pywinauto import Application

app = Application(backend="uia").connect(title='MainWindow')
# app.MainWindow.dump_tree() # useful to get child_window spec for just a copy-paste!

target = app.MainWindow.child_window(title='TARGET', control_type='Edit').wrapper_object()
# maybe try control_type='Text' depending on info from Inspect.exe

# when you found the control, just get the text
target.legacy_properties()['Value'] # .legacy_properties() returns a dict

我没有用真实的应用程序实例检查它。希望你可以调整它的边缘。


推荐阅读