4

Is there a way of writing your own System.Windows.Automation.Condition class? I don't know how this class works because it offers no public method to define the comparison behavior.

Background: I use the UIAutomation library to find elements the user interacts with in order to repeat his actions. Sometimes I find it hard to access an element by its properties like the automation id or the name. Recently I found out that the buttons in the Aero bar of Windows 7 change their names to the name of the selected instance and this really strikes me because I cannot use the exact name for a comparison anymore.

Marcel Bonzelet
  • 238
  • 2
  • 13
  • How about using the AutomationProperties.HelpText as a Tag-like property ? – Maxwell77 Feb 22 '17 at 23:15
  • 2
    I don't have an answer but just wanted to comment I have the same problem. The property value condition, as far as I can tell, only does exact match. I need a condition that takes a regex, or accepts a lambda for a predicate, because the text of the things I need to get changes at runtime. I can't understand why they would make this API and not provide that. It appears they also made it impossible to subclass the search condition, so there's no work around except search all children. – Dennis Mar 08 '17 at 16:28

1 Answers1

0

You can use inspect.exe to see all available properties of any UI element on screen. That will help you understand which properties are you want to use to identify UI element in various cases. For instance: I've found that AutomationId property is very useful in some cases when element name is not static.

Also if you want to find element with partial match of it's Name - you can iterate all tree(For instance: via FindAll method) of available element's with TrueCondition and check name matches manually.

Mikolaytis
  • 921
  • 1
  • 12
  • 27