🚀 Boost your UI Automation skills with these amazing tips from Descolada 🤖
Channel: AUTOHOTKEY Gurus
Date: 2023-01-10

We have another deep-dive into using UIA with AutoHotkey with the author Descolada.   Here we get more great tips and understand how and why to use some approaches over others.  If you're using the UIA library from Descolada, consider donating to him.  It's a lot of work and having a little reward goes a long way   You can donate here:  https://the-Automator.com/Descolada

If you get value out of this video...  https://www.paypal.me/JoeGlines
Check out more of my scripts at: http://the-automator.com 
TLDR: UIA automation can be used to find elements, traverse the tree, detect page structure changes, and track events with event handlers and text patterns.

1. 00:00 🤔 We discussed changes to UIA automation, found a workaround for using "or" in expressions, and discussed tips for creating a library and using enumerations.
 1.1 We're having a chat to see what changes have been made to the UIA automation stuff since the last time we talked.
 1.2 Using an "or" statement in a find by expression did not work, so two separate finds had to be done and then the results merged, but the order was not correct.
 1.3 Expressions can be written with capitalization, parentheses, and operands such as "or" and "not".
 1.4 FindFirstBy uses the same syntax as Hotkey and the second parameter should be the match, with the third parameter being the one that doesn't change.
 1.5 When creating a library, consider trusting everything in Dropbox for better security.
 1.6 Using enumerations as global variables is a useful way to make code more readable and easier to understand.

2. 13:34 🐞 Using UIA, you can use Tree Walker or Find By Path to find elements and handle errors with the "on error" function.
 2.1 You can use both the return statement and the throw statement to handle errors when searching for an element.
 2.2 When designing an application, the user interface should not throw errors, but methods, functions, and libraries should throw errors to notify the main application of an issue.
 2.3 In V2, all functions throw errors under certain conditions, and you can use the "on error" function to log errors and decide whether to display them to the user or not.
 2.4 UIA automatically detects when a variable is misspelled, preventing unexpected errors and saving time in large projects.
 2.5 You can use Tree Walker or Find By Path to find the next button element in the tree.
 2.6 I opened up UI automation and showed 69 differences, stashed changes, and synchronized them.

3. 23:20 🔎 Create a UIA condition object with type document and edit, and use FindByPath to parse the numeric path of an element with tabs or spaces.
 3.1 Create an UIA condition object with type document, then create another condition with type edit, and combine them with an and condition to search for both.
 3.2 Creating an or condition with UIA is complex and annoying, but once you understand the concept it is easier to use.
 3.3 FindByPath returns the first parent of Notepad that matches the specified type, relative to the element you are starting from.
 3.4 The numeric path of an element can be seen in the ACC viewer tool, and can be parsed by separating it with tabs or spaces.
 3.5 It is easier to parse and display data if it is returned with tabs, which can then be replaced with spaces.
 3.6 Try out a tsv parameter to delimit an argument.

4. 36:22 🔎 Use a TreeWalker to traverse the tree and find elements, but be aware of potential modifications to the tree structure.
 4.1 Using a tool like Rainbow CSV can help quickly identify columns in a TLDR by assigning each column its own color.
 4.2 Using a TreeWalker allows you to traverse the tree and get siblings, parents, and other elements that FindFirst cannot.
 4.3 Using a TreeWalker, you can find the parent element and its descendants and children by using FindFirstBuy with the type and name specified.
 4.4 Using tree walker, you can traverse in any direction in the tree to find an element by position.
 4.5 Create a condition and pass it into a TreeWalker to traverse the tree and find elements, but be aware that it may modify the tree structure.
 4.6 To find tags and buttons, use the DOM comparison and note that it may list buttons on the same level even if one is a child of the other.

5. 49:23 🔎 Use TreeWalker's getNextSiblingElement method to find the next element in a tree, or use FindFirst and NormalizeElement to search upwards and downwards respectively.


6. 59:12 🔍 Creating custom tree walkers and caching the tree can improve search performance, while the Focus Changed event can detect page structure changes.

7. 01:10:51 🤔 Use the smallest path possible when using UI automation to track events in UIA and ACC with event handlers and text pattern.

8. 01:20:40 🤩 Making life easier with UI Automation Library, Tricky Dudes and other tools to find elements, filter objects and send keystrokes on Mercy.