【问题标题】:Handling Context Menu of the taskbar icon with pywinauto使用 pywinauto 处理任务栏图标的上下文菜单
【发布时间】:2020-09-23 04:01:28
【问题描述】:

我正在尝试自动化其中一个应用程序的退出操作。该应用程序的图标位于任务栏中。我成功地使用我在 stackoverflow 上找到的修改后的代码打开了该图标的上下文菜单:

import pywinauto
from pywinauto.application import Application
import time

app= "Service is enabled."

app = Application(backend="uia").connect(path="explorer.exe")
st = app.window(class_name="Shell_TrayWnd")
t = st.child_window(title="Notification Chevron").wrapper_object()
t.click()

time.sleep(1)

list_box = Application(backend="uia").connect(class_name="NotifyIconOverflowWindow")
list_box_win = list_box.window(class_name="NotifyIconOverflowWindow")
list_box_win.wait('visible', timeout=30, retry_interval=3)

# time.sleep(1)

appOpened= list_box_win.child_window(title = app)
appOpened.click_input(button = "right")

执行上面的代码后,我到达context menu 打开的位置:

接下来我要做的就是点击Exit,我试过通过指定鼠标点击坐标来做,但是我注意到父图标的位置不时发生变化。 我想做的是获取Exit按钮的句柄并自动发送点击。

-----编辑--------

图标位于隐藏图标中

【问题讨论】:

    标签: python windows automation taskbar pywinauto


    【解决方案1】:

    所以你想访问右键单击上下文菜单。正如this answer 中所说,您可以执行以下操作:

    listbox.PopupMenu["Exit"].set_focus().click_input()
    

    【讨论】:

    • 感谢您的评论,我在问题的代码末尾添加了 list_box_win.PopupMenu["Exit"].set_focus().click_input() 行,但出现匹配错误:MatchError: Could not find 'PopupMenu' in 'dict_keys([different buttons here])
    • 如果我将 list_box_win 替换为 list_box,它会给出同样的错误,但是我的任务栏中的项目的字典
    • 顺便说一下,我正在访问的图标位于隐藏图标中
    • 这是应用程序上下文菜单,因此您必须连接到应用程序并从应用程序对象访问它:通常类似于 app.ContextMenu for backend="uia"。只有托盘图标是explorer.exe 的一部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    相关资源
    最近更新 更多