Kumar Anand
Kumar Anand

Reputation: 11

pywinauto doesn't identify control as a TabControl

Inspect.exe has identified the control as a TabControl, however pywinauto doesn't recognize the same. Image is as below**
Inspect.exe recognises TabControl


dump_tree gives the following, the control type is "C1.Win.C1Command.C1DockingTabPage" which is a 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's HwndWrapper object is not a tabcontrol:

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

Upvotes: 1

Views: 1638

Answers (2)

Prameya R Hegde
Prameya R Hegde

Reputation: 11

You might have used win32 as the backend(this is default). use uia which gives control identifiers for ribbon and tabs. eg:

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

Upvotes: 0

eltio
eltio

Reputation: 104

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.

The solution is to select the tab by ILegacyIAccessibleProvider::DoDefaultAction method.
This code works for 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()

Upvotes: 1

Related Questions