« MBS @ FMTraining.TV -… |
Home |
AI Development with t… »
We’re excited to announce a new set of UIAutomation classes for Xojo in the MBS Xojo Plugins — making it possible to automate and inspect user interfaces on Windows directly from your Xojo applications!
With these new classes, you can use Microsoft’s UI Automation API to interact with elements of other Windows applications. That means you can:
-
Inspect and retrieve information about controls in other programs (windows, buttons, text fields, and more).
-
Automate tasks by invoking clicks, entering text, or reading values from controls.
-
Build your own accessibility or testing tools using native Windows accessibility infrastructure.
-
Verify your own application’s UI behavior during automated testing.
Here’s a short example of how easy it is to get started:
Var UIAutomation As New UIAutomationMBS
Var appElement As UIAutomationElementMBS = UIAutomation.RootElement
// list windows to console to find names
Var ea As UIAutomationElementArrayMBS = appElement.FindAll(UIAutomationMBS.TreeScopeChildren, UIAutomation.CreateTrueCondition)
For Each e As UIAutomationElementMBS In ea.Elements
System.DebugLog e.CurrentName
Next
// put in exact name of window!
Var value1 As Variant = "Hello.txt – Notepad"
Var cond1 As UIAutomationPropertyConditionMBS = UIAutomation.CreatePropertyCondition(UIAutomationElementMBS.PropertyIdName, value1)
Var notepad As UIAutomationElementMBS = appElement.FindFirst(UIAutomationMBS.TreeScopeSubtree, cond1)
If notepad <> Nil Then
MessageBox("Found Notepad window!")
Var ControlTypeDocument As Int32 = UIAutomationElementMBS.ControlTypeDocument
Var value2 As Variant = ControlTypeDocument // must be int32
Var cond2 As UIAutomationPropertyConditionMBS = UIAutomation.CreatePropertyCondition(UIAutomationElementMBS.PropertyIdControlType, value2)
Var docControl As UIAutomationElementMBS = notepad.FindFirst(UIAutomationMBS.TreeScopeSubtree, cond2)
If docControl <> Nil Then
Var textPattern As UIAutomationTextPatternMBS = docControl.CurrentPattern(docControl.PatternIdText)
If textPattern <> Nil Then
// shows text from notepad window
MessageBox(textPattern.DocumentRange.Text)
End If
Else
MessageBox("Document control not found.")
End If
Else
MessageBox("Notepad window not found!")
End If
This snippet locates the Notepad window and queries the text from it automatically — no user interaction required.
UIAutomation opens up a world of possibilities:
-
Automate repetitive testing steps.
-
Develop tools to validate your app’s accessibility and structure.
-
Create scripting utilities that interact with third-party Windows programs.
You can learn more and explore all available classes here:
UIAutomation Classes in MBS Xojo Plugin
We’re looking forward to seeing what you build with it!
If you create something cool using these new classes, please share your experience — we love hearing from developers in the Xojo community.
15 04 26 - 08:17