The application I am automating is a win32 supported backend application and using inspect.exe to detect the elements
Below is my code trying to click on sales receipt element, on execution I get error
code:screenshot of the treeview in inspect.exe while application image in background
app = Application(backend="win32").connect(process=5468)
app.windows()
dlg = app['TFMenuG.UnicodeClass']
handle = dlg.child_window(control_id='UIA_ButtonControlTypeId (0xC350)').draw_outline()
error:
Traceback (most recent call last):
File "c:\..\pythonDemo\notepad.py", line 62, in <module>
handle = dlg.child_window(control_id='UIA_ButtonControlTypeId (0xC350)').draw_outline()
File "C:\..\AppData\Local\Programs\Python\Python39-32\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\..\AppData\Local\Programs\Python\Python39-32\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
raise e.original_exception
File "C:\..\AppData\Local\Programs\Python\Python39-32\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\..\AppData\Local\Programs\Python\Python39-32\lib\site-packages\pywinauto\application.py", line 222, in __get_ctrl
ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
File "C:\..\AppData\Local\Programs\Python\Python39-32\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'control_id': 'UIA_ButtonControlTypeId (0xC350)', 'top_level_only': False, 'parent': <win32_element_info.HwndElementInfo - '', TFMenuG.UnicodeClass, 196780>, 'backend': 'win32'}
Please help me a way to identify the elements. I am doubting the elements are not recognised because of win32 backend
First, if you use
Inspect.exe
you must useApplication(backend="uia")
. If you want to check the application compatibility with older "win32" backend, you need Spy++ which is included into Visual Studio.Second
control_id
is integer ID from Spy++ and it can be inconsistent from run to run. I would recommend printing top level window texts byprint([w.window_text() for w in app.windows()])
and use necessary text to identify top level window and dump child identifiers:P.S. If
Inspect.exe
doesn't show property "NativeWindowHandle", it means the element is not visible to "win32" backend.EDIT1:
Try this code for the "win32" TreeView which is not automatically detected as TreeViewWrapper:
When you see all available methods, try documented methods for "win32" TreeView: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.controls.common_controls.html#pywinauto.controls.common_controls.TreeViewWrapper Please note that
_treeview_element
object returned byget_item(...)
represents specific item without window handle, but it's usable.