[英]pywinauto doesn't identify control as a 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
對象不是HwndWrapper
:
>>> 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毫無例外地退出,但實際上對給定的小部件沒有任何作用。
解決方案是通過ILegacyIAccessibleProvider::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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.