Search code examples
pythonautomationpywinauto

How to select a dataitem based on text value in DataGrid


I'm trying to find and select a record inside a data grid. (im automating an app using pywinauto)

enter image description here

above image is sample of what I'm trying to locate and select (scenario is to either delete or modify the record)

If its showing like this, i can use a straight foward code e.g. app.Dialog.child_window(title="name1690963953988603900", control_type="Text").click_input

However, if its not scrolled down (record is not visible in the eye), it returns an error

Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\site-packages\pywinauto\application.py", line 250, in __resolve_control
    ctrl = wait_until_passes(
           ^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
    raise err
pywinauto.timings.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\get object project\ObjectIdentification.py", line 22, in <module>
    app.Dialog.child_window(title="name1690963953988603900", control_type="Text").click_input()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
    ctrls = self.__resolve_control(self.criteria)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
    raise e.original_exception
  File "C:\Program Files\Python311\Lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
    func_val = func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\pywinauto\application.py", line 222, in __get_ctrl
    ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
    raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'title': 'name1690963953988603900', 'control_type': 'Text', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'Merlot.Aero', Window, 266712>, 'backend': 'uia'}

Process finished with exit code 1

the scrollbar itself has no properties upon checking via inspect tool. Is there a way to automatically scroll inside the datagrid then click the text?

Hope someone can assist me on this. many thanks.

expected result is to automatically scroll when item is not visible in the current screen (if record is at the very last row in the grid)


Solution

  • try app.Dialog.dump_tree() or app.window().dump_tree() to print tree for all element like:enter image description here