1

我正在尝试使用 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

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

4

1 回答 1

0

重新格式化::

代码

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()需要一个字符串。

希望有帮助

于 2010-06-14T09:38:22.390 回答