Skip to content
Marko Ristin edited this page Nov 4, 2020 · 10 revisions

Base concepts

FlaUI has some base concepts / classes that should be known when using FlaUI. The most important classes are described in this section.

AutomationElement

All ui elements are wrapped in an AutomationElement by FlaUI. This object contains the most useful methods when interacting with ui elements.
There are various As... methods which just wrap the AutomationElement into another class (inherited from AutomationElement which usually contains more methods for easy interaction). For example the AsTextBox returns a TextBox object which contains a Text property which takes care of everything and just allows you to set or get the text of the TextBox.
The AutomationElement allows you to get back all available native UIA methods and properties so you can implement your own controls as a subclass of an AutomationElement.

AutomationProperty

Properties of an ui element or an ui pattern are wrapped in AutomationProperty objects. There are different possibilities to access the effective value thru this object:

  • Value - Directly gets the value. Will throw if the value is not supported or if you are in a cache request and the value was not cached
  • ValueOrDefault - Will get the value or the default value if it is not supported. Will still throw if you are in a cache request and the value was not cached.
  • TryGetValue - Tries to get the value and returns true, if it is available and false, if it is not supported. Throws if you are in a cache request and the value was not cached.

There is also an implicit cast implemented. So if you do string name = myElement.Properties.Name it will automatically use the ValueOrDefault and return that value directly.

AutomationPattern

UIA provides a bunch of patterns which can be implemented by controls. For example the Grid usually implements and provides the GridPattern which allows to access rows and cells.
FlaUI wraps all patterns and allows accessing them with the .Pattern property on any AutomationElement. The pattern object provides several possibilities to access the pattern:

  • Pattern - Returns the pattern object. Throws if the pattern is not supported.
  • PatternOrDefault - Returns the pattern object or null, if the pattern is not supported.
  • TryGetPattern - Returns true if the pattern is supported and false otherwise.
  • IsSupported - A simple flag to show, if a pattern is supported or not

Examples

Getting the value from an element that supports the value pattern

Here is an example on how to get the value of an element that supports a value pattern:

myElement.Patterns.Value.Pattern.Value.Value

This line looks rather strange but it absolutely makes sense. Here's a small description of the parts:

  • myElement is the element with the value pattern
  • Patterns is a container with all patterns
  • Value is the pattern we want
  • Pattern returns the pattern object
  • Value is the Value property object of the pattern
  • Value is the effective value of the property

CI Tests

FlaUI contains a lot of tests with are run in the CI when building.
These tests can be a very good start to see, what FlaUI is capable of and to get some ideas on how to use it.
You can get those tests by cloning FlaUI and checking out the project FlaUI.Core.UITests.