3

我正在使用 pywinauto 列出特定应用程序的控件标识符。我可以做到这一点。但是,我想将这些控件标识符保存到文件中,或者更好地将它们分配给字符串或列表,但不能写入或分配它们....有谁知道以编程方式将这些标识符保存到文件或内存中的方法?

示例代码:

import os
import time
from pywinauto import application
from SendKeys import SendKeys


app=application.Application()
app.start_(r"C:\Program Files\myapp.exe")


app.dlg.print_control_identifiers()

Control Identifiers:
Button - 'Exit'   (L900, T649, R975, B672)
        'Button' 'Button0' 'Button1' 'Exit' 'ExitButton'
Button - 'About'   (L339, T646, R410, B672)
        'About' 'AboutButton' 'Button2'
...
...
...

我尝试了以下方法:

my_App_ci = app.dlg.print_control_identifiers()

和:

my_App_ci = []
my_App_ci.append(app.dlg.print_control_identifiers())

无济于事....

4

2 回答 2

5

您可以使用 print_control_identifiers(filename="path\to\your\desktop\file.txt")

于 2018-01-16T13:40:09.000 回答
2

print_control_identifiers prints to stdout instead of returning a string. I did a quick look at the source and I could not see any functions to get them as strings, which is pretty crappy design IMHO.

You could capture the information by reassigning sys.stdout to an StringIO object and get the string from that. Or read the source to see what print_control_identifiers does and make a version that returns a list of strings.

于 2013-03-25T17:59:26.263 回答