4

我正在尝试使用 python 在 Windows 7 中查找并单击任务栏上的隐藏图标(通过单击白色三角形显示)。我一直在尝试为此使用 pywinauto,但它似乎没有找到并单击这些隐藏图标之一的功能。甚至 pywinauto 中的任务栏模块也不起作用(可能是由于已过时)。我怎样才能做到这一点?

我尝试访问以实现自动化的应用程序只能通过单击任务栏中的隐藏图标来显示。通过隐藏图标,我的意思是在通知区域。

我试过 pywinauto.taskbar.SystemTrayIcons,但 DrawOutline 方法显示这是任务栏的错误区域。并且使用 taskbar.SystemTrayIcons.WrapperObject().Button(0) 无论如何都不起作用,但会给出 GetButtonInfo failed 异常。

我还尝试使用 SWAPY 创建用于查找和单击相关按钮的 python 代码,虽然它可以单击按钮(有用地命名为“按钮”)来显示隐藏的图标,但它没有显示如何单击这些图标。

4

1 回答 1

3

Install latest version of pywinauto on 64-bit Python (2.7 or 3.4, it doesn't matter) and run the following code:

from pywinauto import taskbar
taskbar.TaskBar.Button.click_input()
popup_dlg = taskbar.explorer_app.window(class_name='NotifyIconOverflowWindow')
popup_toolbar = popup_dlg.Overflow_Notification_Area
print(popup_toolbar.texts()[1:])

Further you can press interested button based on retrieved texts:

popup_toolbar.button('your program name').click_input(double=True)

EDIT (2019, January): this code may not work for latest Windows 10 RS1+ because notification icons area was changed significantly, though it should work for Win7 and Win8.1.

于 2015-04-15T15:27:04.847 回答