Using PyWinAuto (or anything else) to interact with hidden icons on the taskbar

拈花ヽ惹草 提交于 2019-12-10 06:58:11

问题


I am trying to find and click a hidden icon on the taskbar (shown by clicking the white triangle) in windows 7, using python. I've been trying to use pywinauto for this, but it doesn't seem to have the functionality to find and click one of these hidden icons. Even the taskbar module in pywinauto doesn't work (possibly due to being outdated). How can I do this?

The application I am trying to access for automation can only be shown by clicking on its hidden icon in the taskbar. By hidden icon, I mean in the notification area.

I've tried pywinauto.taskbar.SystemTrayIcons, but the DrawOutline method shows that this is the wrong area of the taskbar. And using taskbar.SystemTrayIcons.WrapperObject().Button(0) does not work anyway, but gives a GetButtonInfo failed exception.

I've also tried using SWAPY to create python code for finding and clicking the relevant buttons, and although it can click the button (helpfully named 'Button') to show the hidden icons, it does not show how to then click those icons.


回答1:


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.



来源:https://stackoverflow.com/questions/29631404/using-pywinauto-or-anything-else-to-interact-with-hidden-icons-on-the-taskbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!