使用 pywinauto 访问窗口任务栏的按钮(即运行应用程序)



我想访问窗口任务栏中的按钮(如IE,资源管理器等(。我需要某个按钮的自动化 ID。

如果我使用Visual UI Automation工具,我看到按钮位于工具栏"正在运行的应用程序"(类MSTaskListWClass(中。

(对不起,我不能发布图片,因为这是我的第一篇文章(

我尝试:

>>> taskbar.RunningApplications
<pywinauto.application.WindowSpecification object at 0x02F5C830>
>>> taskbar.RunningApplications.children()
[]

=>我不明白,因为正在运行的应用程序任务栏不为空(至少当前的cmd应用程序(

我也尝试:

from pywinauto.application import Application
from pywinauto import Desktop
import pywinauto 
import re as regex
def dump(o):
s = ("name %s ClassName %s Hdler %s" % (o.name.encode('utf-8'),o.class_name.encode('utf-8'),hex(o.handle)))
return s 
# Point d'entree l 1
l1 = pywinauto.findwindows.find_elements(class_name_re = 'Shell_TrayWnd')
print("Lg %d - %s" % (len(l1),dump(l1[0])))   
l2 = pywinauto.findwindows.find_elements(class_name_re = 'ReBarWindow32')
print l2    
shell_TrayWnd = l1[0]
l3 =  shell_TrayWnd.children()  
for i in range(len(l3)): 
if regex.search('MSTaskSwWClass',l3[i].class_name):
print ("Fuundl3[%2d] %s" % (i, dump(l3[i]))) 
listButton = l3[i].children()[0]
print("listButton  %s" % (dump(listButton))) 
print listButton.children()

这是示例问题:正在运行的应用程序列表似乎为空。

所以我的问题是:

  • pywauto的不良用法?
  • 按钮是 MSTaskListWClass GUi 元素的子级吗?Visual UI 自动化工具为每个按钮提供0x00作为处理程序。这很奇怪
  • Bug in pywinauto ?问题似乎出在 pywinauto 0.61 或 0.65 中
  • 这是不可能的 pywinauto ?
  • 如果我成功访问正在运行的应用程序按钮,是否可以读取 AutomationId 字段?

感谢您的想法或任何指示, 菲努克斯

find_elements是一个不建议直接使用的低级函数(我在入门指南中没有提到它(。这段代码对我有用:

from pywinauto import Application
app = Application(backend="uia").connect(title='Taskbar') # backend is important!!!
#app.Taskbar.dump_tree() # was needed for next step, just copied child_window spec from here
running_apps = app.Taskbar.child_window(title="Running applications", control_type="ToolBar")
print([w.window_text() for w in running_apps.children()])
# running_apps.dump_tree() # another debug print for auto_id properties advice

相关内容

最新更新