[英]pywinauto - how to right-click in systemtray, select an item then subitem
我在 Windows 10 系统托盘的隐藏部分中有一个应用程序。我正在尝试连接到该应用程序,右键单击它,然后选择“关于”之类的内容。 我明白,一旦我有了目标应用程序,我需要连接到应用程序,我在代码的第 25 行执行了此操作,但我无法从那里走得更远。
这是我到目前为止的代码:
from pywinauto import Application
import time
app = Application(backend="uia").connect(path="explorer.exe")
systemTray = app.window(class_name="Shell_TrayWnd")
systemTray.child_window(title="Notification Chevron").click_input(button="left")
#systemTray.print_control_identifiers()
time.sleep(0.25)
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)
# List all the icons in the systray
for notification_area in list_box_win.children():
for app_in_tray in notification_area.children():
print(str(app_in_tray))
target_app = list_box_win.child_window(title="TrayStatus Pro Trial 4.6\r\nCaps Lock: Off")
target_app.wait('visible', timeout=30, retry_interval=3)
target_app.click_input(button="right")
target_app.target_app.print_control_identifiers()
target_app.dump_tree()
sysapp = Application().connect(path='TrayStatus.exe')
sysapp.menu_select('About') #This part fails
Application()
类表示应用程序,有时它无法识别窗口。 话虽如此,您在开始使用UIA
后端时并没有提到应用程序的后端,因此还要找出行sysapp = Application().connect(path='TrayStatus.exe')
并添加,还添加connect()
的timeout=10
参数可以多次使用。
如果上述选项对您不起作用,请尝试使用Desktop
类。 再次,您可以提及您选择的后端和兼容性,没有这样的方法来识别应用程序的后端。
window2 = Desktop(backend="win32").window(title='title of the rayStatus.exe window')
您将需要导入 -
from pywinauto import Desktop
。
最后,您可以使用打印窗口的标题
list_window = Desktop().windows()
for window in list_window:
window.window_texts() # this should print the all open window names on desktop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.