pywinauto不能将控件标识为TabControl

时间:2019-03-15 11:56:50

标签: python pywinauto

Inspect.exe已将控件标识为TabControl,但是pywinauto无法识别该控件。图片如下**
Inspect.exe recognises TabControl


dump_tree给出以下内容,控件类型为"C1.Win.C1Command.C1DockingTabPage",即component one tabcontrol

Control Identifiers:

WindowsForms10.Window.8.app.0.13965fa_r6_ad1 - ''    (L42, T31, R1334, B694)
['Alloy Configuration TypeWindowsForms10.Window.8.app.0.13965fa_r6_ad11', 'Alloy Configuration TypeWindowsForms10.Window.8.app.0.13965fa_r6_ad1', 'Alloy Configuration TypeWindowsForms10.Window.8.app.0.13965fa_r6_ad10', 'WindowsForms10.Window.8.app.0.13965fa_r6_ad10', 'WindowsForms10.Window.8.app.0.13965fa_r6_ad1', 'WindowsForms10.Window.8.app.0.13965fa_r6_ad11']
child_window(auto_id="AlloyTabDocument", control_type="C1.Win.C1Command.C1DockingTab")
   | 
   | WindowsForms10.Window.8.app.0.13965fa_r6_ad1 - 'Alloy Configuration'    (L240, T32, R1333, B693)
   | ['Alloy Configuration', 'Alloy ConfigurationWindowsForms10.Window.8.app.0.13965fa_r6_ad1', 'WindowsForms10.Window.8.app.0.13965fa_r6_ad12']
   | child_window(title="Alloy Configuration", auto_id="tabAlloyConfiguration", control_type="C1.Win.C1Command.C1DockingTabPage")

pywinauto的HwndWrapper对象不是Tab控件:

>>> AlloyTabDocument  = addConfigWnd.child_window(auto_id="AlloyTabDocument")
>>> print(AlloyTabDocument.wrapper_object())
hwndwrapper.HwndWrapper - '', WindowsForms10.Window.8.app.0.13965fa_r6_ad1

1 个答案:

答案 0 :(得分:1)

这个问题的根本原因是 MS UI 自动化方法 SelectionItemPattern.Select 无一例外地退出,但实际上对给定的小部件没有任何作用。

解决办法是通过ILegacyIAccessibleProvider::DoDefaultAction方法选择tab。
此代码适用于 pywinauto 0.6.8:

import pywinauto
from pywinauto.application import Application
import pywinauto.uia_defines as uia_defs

app = Application(backend="uia").connect(path='wfControlExplorer.exe')
explorer = app.window(class_name="WindowsForms10.Window.8.app.0.1a8c1fa_r14_ad1", auto_id='Explorer')
overview = explorer.child_window(class_name='WindowsForms10.Window.8.app.0.1a8c1fa_r14_ad1', auto_id='Overview')
tabs = overview.child_window(class_name="WindowsForms10.Window.8.app.0.1a8c1fa_r14_ad1", control_type="Tab")
# tabs.dump_tree()
# tabs.select(2)
uia_defs.get_elem_interface(tabs.children()[2].element_info.element, "LegacyIAccessible").DoDefaultAction()