I'm currently working on recording data from a desktop application with a relatively static UI structure. The UI includes elements like comboboxes, checkboxes, grids, and buttons. However, when searching for elements, particularly in a large grid with thousands of cells, the process takes a significant amount of time and causes the application to hang.
For example The UI tree looks something like this:
- Pane
- Pane
- Pane
- Combobox (Automation ID: cmbaccount)
- List Item 1 (Selected: 0)
- List Item 2 (Selected: 1)
- List Item 3 (Selected: 0)
- Combobox (Automation ID: cmbcountry)
- List Item 1 (Selected: 0)
- List Item 2 (Selected: 1)
- List Item 3 (Selected: 0)
- Grid (containing a large number of cells)
- Combobox (Automation ID: cmbname)
- List Item 1 (Selected: 0)
- List Item 2 (Selected: 1, currently displaying "John")
- List Item 3 (Selected: 0)
- Combobox (Automation ID: cmbaccount)
- Pane
- Pane
When I need to retrieve updated values from these comboboxes, I have to search for the combobox elements again within the unchanged UI structure. This results in significant delays and hangs in the application.
Is there an approach to expedite the process of searching for these combobox elements and eliminate the lag experienced by the application when the FindFirst function is called in a large UI tree?
I've experimented with storing automation elements after initially searching for them.
For example:
IUIAutomationCondition condition = automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "cmbname");
IUIAutomationElement targetElement = currentWin.FindFirst(TreeScope.TreeScope_Descendants, condition);
i've tried caching the targetElement in a dictionary: { "cmbname" : targetElement }
This approach allows us to retrieve the new value from the combobox after it has been changed. However, it has limitations. When we close the window, the cached elements become invalid for the new window.
I also explored using built-in caching mechanisms, but they present challenges. Changes to the elements are not automatically reflected in the cached values, and determining when to build an updated cache is not straightforward.
I am seeking advice on how to effectively cache and manage automation elements, considering the limitations and complexities we've encountered. Any insights or recommendations on improving this caching strategy would be greatly appreciated.
Is there a way to serialize the tree on disk and then load the tree from disk before recording from actual application will this help speeding up the search first time ?