简体   繁体   English

pywinauto 不会将控件识别为 TabControl

[英]pywinauto doesn't identify control as a TabControl

Inspect.exe has identified the control as a TabControl, however pywinauto doesn't recognize the same. Inspect.exe已将该控件标识为 TabControl,但是 pywinauto 无法识别相同的控件。 Image is as below**图像如下**
Inspect.exe recognises TabControl Inspect.exe 识别 TabControl


dump_tree gives the following, the control type is "C1.Win.C1Command.C1DockingTabPage" which is a component one 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's HwndWrapper object is not a tabcontrol: pywinauto 的HwndWrapper对象不是HwndWrapper

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

The root cause of this problem is MS UI Automation method SelectionItemPattern.Select exits without any exception, but actually does nothing with the given widget.这个问题的根本原因是 MS UI 自动化方法SelectionItemPattern.Select毫无例外地退出,但实际上对给定的小部件没有任何作用。

The solution is to select the tab by ILegacyIAccessibleProvider::DoDefaultAction method.解决方案是通过ILegacyIAccessibleProvider::DoDefaultAction方法选择选项卡。
This code works for pywinauto 0.6.8:此代码适用于 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()

You might have used win32 as the backend(this is default).您可能使用 win32 作为后端(这是默认设置)。 use uia which gives control identifiers for ribbon and tabs.使用 uia 为功能区和选项卡提供控件标识符。 eg: x=Application(backend='uia').connect(title="window name",timeout=10) x.windowname.print_control_identifiers()例如:x=Application(backend='uia').connect(title="window name",timeout=10) x.windowname.print_control_identifiers()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM