pywinauto 不会将控件标识为 TabControl



Inspect.exe已将控件识别为tabcontrol,但是pywinauto却不识别。图像如下**
Inspect.exe识别TabControl


dump_tree给出以下内容,控制类型是"C1.Win.C1Command.C1DockingTabPage",它是一个组件一个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对象不是TabControl:

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

此问题的根本原因是MS UI自动化方法selectionItemPattern.SELECT退出而没有任何例外,但实际上对给定的小部件没有任何作用。

解决方案是选择ilegacyiaccessible provider :: DodeFaultAction方法的选项卡。
此代码适用于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()

您可能已经将Win32用作后端(这是默认值)。使用UIA为功能区和选项卡提供控制标识符。例如:

x=Application(backend='uia').connect(title="window name",timeout=10)
    x.windowname.print_control_identifiers()

最新更新