【问题标题】:How to print the Control identifiers of a window to a document in Pywinauto如何在 Pywinauto 中将窗口的控件标识符打印到文档中
【发布时间】:2010-06-14 06:44:48
【问题描述】:

我正在尝试使用 Pywinauto 自动安装应用程序。在安装过程中,最后一个窗口在少数情况下会显示一些警告或错误消息,然后系统开始重新启动。我的目标是捕获可能的警告消息

app.top_window_()._ctrl_identifiers()
np.Notepad.Edit.TypeKeys(a,with_spaces=True, with_tabs=True, with_newlines=True)

这将返回一个列表,其中包含屏幕上的所有消息。 第二行是我试图在记事本中打印列表对象的地方,但它抛出了一些异常

Traceback (most recent call last):
  File "<pyshell#37>", line 1, in <module>
    np.Notepad.Edit.TypeKeys(a,with_spaces=True, with_tabs=True, with_newlines=True)
  File "C:\Python26\pywinauto\controls\HwndWrapper.py", line 950, in TypeKeys
    turn_off_numlock)
  File "C:\Python26\pywinauto\SendKeysCtypes.py", line 629, in SendKeys
    keys = parse_keys(keys, with_spaces, with_tabs, with_newlines)
  File "C:\Python26\pywinauto\SendKeysCtypes.py", line 538, in parse_keys
    c = string[index]
KeyError: 0

谁能告诉我如何做到这一点,或者是否有其他方法可以通过示例来处理?

【问题讨论】:

    标签: pywinauto


    【解决方案1】:

    重新格式化::

    代码

    app.top_window_()._ctrl_identifiers()  # did you mean print_control_identifiers() ?
    np.Notepad.Edit.TypeKeys(a,with_spaces=True, with_tabs=True, with_newlines=True)
    

    追溯

    Traceback (most recent call last): 
    File "", line 1, in 
        np.Notepad.Edit.TypeKeys(a,with_spaces=True, with_tabs=True, with_newlines=True) 
    File "C:\Python26\pywinauto\controls\HwndWrapper.py", line 950, in TypeKeys 
        turn_off_numlock) 
    File "C:\Python26\pywinauto\SendKeysCtypes.py", line 629, in SendKeys 
        keys = parse_keys(keys, with_spaces, with_tabs, with_newlines) 
    File "C:\Python26\pywinauto\SendKeysCtypes.py", line 538, in parse_keys 
        c = string[index] KeyError: 0
    

    您没有解释第二行 a 包含的内容,但看起来您传递的是字典而不是字符串。 SendKeys() 需要一个字符串。

    希望有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 1970-01-01
      相关资源
      最近更新 更多