FindTopAutomationWindows
IList<AutomationControl> FindTopAutomationWindows(string wantedText);
IList<AutomationControl> FindTopAutomationWindows(string wantedText, ControlType controlType);
IList<AutomationControl> FindTopAutomationWindows(string wantedText, string wantedClass);
IList<AutomationControl> FindTopAutomationWindows(string wantedText, TextMatch textMatch);
IList<AutomationControl> FindTopAutomationWindows(string wantedText, string wantedClass, TextMatch textMatch);
IList<AutomationControl> FindTopAutomationWindows(string wantedText, TextMatch textMatch, ControlType controlType);
IList<AutomationControl> FindTopAutomationWindows(ControlType controlType);
IList<AutomationControl> FindTopAutomationWindows(Predicate<AutomationControl> selectionFunction);
Parameters
wantedText:
The text caption of the Control. The default match criteria is contains, case insensitive. This value can be none or an empty string "" if you are only matching on wantedClass.
textMatch:
Options are TextMatch.Contains (default), TextMatch.Exact, TextMatch.StartsWith, TextMatch.EndsWith, TextMatch.MatchCase See TextMatch.
wantedClass:
The window class name
controlType:
The Windows AutomationElement System.Windows.Automation. ControlType
type e.g. ControlType
.Button
selectionFunction:
A reference to a user supplied selection function. See SelectionFunction
Return Value
A list of Control objects that can be used to access the found windows.
Remarks
This method is similar to FindTopAutomationWindow but is used where there may be multiple windows matching the selection criteria.
The window can be matched on caption, a caption and a class name, or a custom selection function. If no matching windows are found an empty list is returned. There is no time delay on this method.
The depth of the tree searched is limited to MaxSearchDepth, default value is 3.
Example
IList<AutomationControl> windows1 = FindTopAutomationWindows("", "className"); // return all top level windows with the class "className"
IList<AutomationControl> windows = FindTopAutomationWindows("Microsoft Word", TextMatch.EndsWith); // find all windows with caption ending with "Microsoft Word"
WriteMessage("num windows=" + windows.Count.ToString());
if (windows.Count < 1)
{
Error("Insufficient windows found");
ExitVU();
}
else
{
for (int i = 0; i < windows.Count; i++)
{
WriteMessage("Caption=" + windows[i].Text);
}
// Alternate method
foreach (AutomationControl w in windows)
{
WriteMessage("Caption=" + w.Text);
}
}
AutomationControl window = FindTopAutomationWindows("", "className")[0]; // get first window of this class
Related: