本文整理汇总了C#中System.Windows.Automation.AutomationElement.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# AutomationElement.FindAll方法的具体用法?C# AutomationElement.FindAll怎么用?C# AutomationElement.FindAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Automation.AutomationElement
的用法示例。
在下文中一共展示了AutomationElement.FindAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunTestInternal
private static void RunTestInternal(IEnumerable<AutomationTest> automationTests, AutomationElement element, IWin32Window parentWindow, AutomationTestManager manager)
{
//create window
RunningTestsWindow testWindow = new RunningTestsWindow();
if (manager._testChildren)
{
//// Determine if this is a control/pattern/Automation test
//// Construct the PropertyCondition
Condition condition = null;
//// Add all the tests
foreach (AutomationTest test in automationTests)
{
// The tests are within a class the defines what pattern type this in is
StringBuilder buffer = new StringBuilder(((MainWindow)parentWindow)._automationTests._testsTreeView.SelectedNode.FullPath);
switch (test.Type)
{
case TestTypes.AutomationElementTest:
// Tests\Automation Element Tests\Priority 2 Tests\AutomationElement.PropertyChange.Enabled.1
condition = Condition.TrueCondition;
break;
case TestTypes.ControlTest:
{
// Tests\Control Tests\Slider\Priority 1 Tests\BulkAdd.1
buffer.Replace(@"Tests\Control Tests\", "");
int indexOf = buffer.ToString().IndexOf(@"\");
buffer.Remove(indexOf, buffer.Length - indexOf);
condition = new PropertyCondition(AutomationElement.ControlTypeProperty, GetControlType(buffer.ToString()));
}
break;
case TestTypes.PatternTest:
{
// Tests\Pattern Tests\Grid\Priority 1 Tests\GridPattern.S.1.1/2/3
buffer.Replace(@"Tests\Pattern Tests\", "");
int indexOf = buffer.ToString().IndexOf(@"\");
buffer.Remove(indexOf, buffer.Length - indexOf);
condition = new PropertyCondition(GetProperty("Is" + buffer.ToString() + "PatternAvailableProperty"), true);
}
break;
default:
throw new ArgumentException("Cannot run " + test.Type + " tests");
}
//// Find all elements
AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, condition);
foreach (AutomationElement temp in collection)
testWindow.AddTest(test, temp);
}
}
else
{
//add all tests
foreach (AutomationTest test in automationTests)
testWindow.AddTest(test, element);
}
//let them run
testWindow.ShowAndRunTests(manager, parentWindow);
}
示例2: TextPatternRangeFromChildGood
public static void TextPatternRangeFromChildGood(AutomationElement element)
{
object patternObj = null;
if (GetPatternObject(element, TextPattern.Pattern, ref patternObj))
{
TextPattern pattern = (TextPattern)patternObj;
Dump("TextPattern.GetVisibleRanges", true, element);
try
{
AutomationElementCollection collection = element.FindAll(TreeScope.Subtree, Condition.TrueCondition);
object property = pattern.RangeFromChild(collection[_rnd.Next(collection.Count)]);
}
catch (Exception exception)
{
VerifyException(element, exception,
typeof(ElementNotAvailableException),
typeof(InvalidOperationException));
}
}
}
示例3: FindElementsByName
// 指定したName属性に一致するAutomationElementをすべて返します
private static IEnumerable<AutomationElement> FindElementsByName(AutomationElement rootElement, string name)
{
return rootElement.FindAll(
TreeScope.Element | TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, name))
.Cast<AutomationElement>();
}
示例4: GetAllChildNodes
public AutomationElementCollection GetAllChildNodes(AutomationElement element, AutomationProperty automationProperty, object value, TreeScope treeScope)
{
var allChildNodes = element.FindAll(treeScope, GetPropertyCondition(automationProperty, value));
if (allChildNodes == null)
throw new ElementNotAvailableException("Not able to find the child nodes of the element");
return allChildNodes;
}
示例5: FindElementByClassName
public static AutomationElementCollection FindElementByClassName(AutomationElement parentElement, string className, ControlType type)
{
PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);
PropertyCondition IDCondition = new PropertyCondition(AutomationElement.ClassNameProperty, className);
AndCondition andCondition = new AndCondition(typeCondition, IDCondition);
return parentElement.FindAll(TreeScope.Element | TreeScope.Descendants, andCondition);
}
示例6: StartApp
/// <summary>
/// 启动 被测试程序.
/// </summary>
public void StartApp()
{
Console.WriteLine("尝试启动程序:[{0}]", APP_NAME);
// 启动被测试的程序
process = Process.Start(APP_NAME);
// 当前线程休眠2秒.
Thread.Sleep(DEFAULT_SLEEP_TIME);
// 获得对主窗体对象的引用
testMainForm = AutomationElement.FromHandle(process.MainWindowHandle);
// 计算器层次下,首先是一个 Pane.
AutomationElementCollection panes = testMainForm.FindAll(TreeScope.Children,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane));
// 获取主窗体上的所有按钮.
testAllButtons = panes[0].FindAll(TreeScope.Children,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));
// 获取主窗体上的所有文本框.
testAllText = panes[0].FindAll(TreeScope.Children,
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));
}
示例7: FindAll
internal static IEnumerable<AutomationElement> FindAll(
AutomationElement parent,
TreeScope scope,
Condition condition,
int timeout)
{
var dtn = DateTime.Now.AddMilliseconds(timeout);
// ReSharper disable once LoopVariableIsNeverChangedInsideLoop
while (DateTime.Now <= dtn)
{
var elements = parent.FindAll(scope, condition);
if (elements.Count > 0)
{
return elements.Cast<AutomationElement>();
}
}
return Enumerable.Empty<AutomationElement>();
}
示例8: GetCurrentUrl
private string GetCurrentUrl(AutomationElement chrome)
{
try
{
string url = null;
var edits = chrome.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
if (edits.Count == 0) return null;
foreach (AutomationElement edit in edits)
{
url = ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;
if (!string.IsNullOrWhiteSpace(url))
return base.GetUrl(url);
}
}
catch
{ }
return null;
}
示例9: GetChildren
public static AutomationElement GetChildren(AutomationElement parent, string NameStartsWith = "", string ControlTypeStartsWith = "")
{
if (parent == null) {
throw new ArgumentException();
}
AutomationElementCollection collection = parent.FindAll(TreeScope.Children, Condition.TrueCondition);
if (collection != null) {
//Cast AutomationElementCollection into
//AutomationElement List
List<AutomationElement> aeList = new List<AutomationElement>(collection.Cast<AutomationElement>());
AutomationElement aeSelected = null;
if (NameStartsWith == "" && ControlTypeStartsWith == "") return null;
if (NameStartsWith != "" && ControlTypeStartsWith == "") {
aeSelected = aeList.FirstOrDefault(i => i.Current.Name.Contains(NameStartsWith));
}
if (NameStartsWith == "" && ControlTypeStartsWith != "") {
aeSelected = aeList.FirstOrDefault(i => i.Current.LocalizedControlType.Contains(ControlTypeStartsWith));
}
if (NameStartsWith != "" && ControlTypeStartsWith != "") {
aeSelected = aeList.FirstOrDefault(i => i.Current.Name.Contains(NameStartsWith));
if (aeSelected == null) aeSelected = aeList.FirstOrDefault(i => i.Current.LocalizedControlType.Contains(ControlTypeStartsWith));
}
if (aeSelected != null)
return aeSelected;
else {
return null;
}
} else {
// some error occured
return null;
}
}
示例10: UIA_ClickButtonByName
//**************************************************************************************************************************************************************
public static void UIA_ClickButtonByName(AutomationElement uiaWindow, Window window, string name)
{
Logger.logMessage("Function call @ :" + DateTime.Now);
try
{
PropertyCondition textCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
AutomationElementCollection buttons = uiaWindow.FindAll(TreeScope.Descendants, textCondition);
foreach (AutomationElement e in buttons)
{
if (e.Current.Name.Equals(name))
{
TestStack.White.UIItems.Button t = new TestStack.White.UIItems.Button(e, window.ActionListener);
t.Click();
}
}
Thread.Sleep(int.Parse(Execution_Speed));
Logger.logMessage("UIA_ClickButtonByName " + uiaWindow + "->" + window + "->" + name + " - Successful");
Logger.logMessage("------------------------------------------------------------------------------");
}
catch (Exception e)
{
Logger.logMessage("UIA_ClickButtonByName " + uiaWindow + "->" + window + "->" + name + " - Failed");
Logger.logMessage(e.Message);
Logger.logMessage("------------------------------------------------------------------------------");
String sMessage = e.Message;
LastException.SetLastError(sMessage);
throw new Exception(sMessage);
}
}
示例11: SearchByTextViaUIA
internal void SearchByTextViaUIA(
GetControlCmdletBase cmdlet,
AutomationElement inputObject,
System.Windows.Automation.AndCondition conditionsForTextSearch)
{
this.WriteVerbose(cmdlet, "Text search");
AutomationElementCollection textSearchCollection = inputObject.FindAll(TreeScope.Descendants, conditionsForTextSearch);
if (null != textSearchCollection && 0 < textSearchCollection.Count) {
this.WriteVerbose(cmdlet, "There are " + textSearchCollection.Count.ToString() + " elements");
foreach (AutomationElement element in textSearchCollection) {
aeCtrl.Add(element);
}
}
}
示例12: SearchByExactConditionsViaUIA
internal void SearchByExactConditionsViaUIA(
GetControlCmdletBase cmdlet,
AutomationElement inputObject,
System.Windows.Automation.AndCondition conditions)
{
#region the -First story
// 20120824
//aeCtrl =
// 20120921
#region -First
// if (cmdlet.First) {
// AutomationElement tempFirstElement =
// inputObject.FindFirst(
// System.Windows.Automation.TreeScope.Descendants,
// conditions);
// if (null != tempFirstElement) {
// if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
// aeCtrl.Add(tempFirstElement);
// } else {
// if (testControlWithAllSearchCriteria(
// cmdlet,
// cmdlet.SearchCriteria,
// tempFirstElement)) {
// aeCtrl.Add(tempFirstElement);
// }
// }
// }
// } else {
#endregion -First
// 20120823
//cmdlet.InputObject.FindFirst(System.Windows.Automation.TreeScope.Descendants,
// 20120824
// 20120917
#region -First
// }
#endregion -First
//else if (UIAutomation.CurrentData.LastResult
#endregion the -First story
//internal void SearchByExactConditionsViaUIA(System.Windows.Automation.AndCondition conditions, ref bool notTextSearch, ref System.Windows.Automation.AndCondition conditionsForWildCards, ref AutomationElement inputObject, ref int processId, GetControlCmdletBase cmdlet)
//{
if (conditions != null) {
if (inputObject != null && (int)inputObject.Current.ProcessId > 0) {
AutomationElementCollection tempCollection = inputObject.FindAll(System.Windows.Automation.TreeScope.Descendants, conditions);
foreach (AutomationElement tempElement in tempCollection) {
if (null == cmdlet.SearchCriteria || 0 == cmdlet.SearchCriteria.Length) {
aeCtrl.Add(tempElement);
cmdlet.WriteVerbose(cmdlet, "ExactSearch: element added to the result collection");
} else {
cmdlet.WriteVerbose(cmdlet, "ExactSearch: checking search criteria");
if (testControlWithAllSearchCriteria(cmdlet, cmdlet.SearchCriteria, tempElement)) {
cmdlet.WriteVerbose(cmdlet, "ExactSearch: the control matches the search criteria");
aeCtrl.Add(tempElement);
cmdlet.WriteVerbose(cmdlet, "ExactSearch: element added to the result collection");
}
}
}
}
}
}
示例13: HelperGetContainersSelectableItems
/// -------------------------------------------------------------------
/// <summary></summary>
/// -------------------------------------------------------------------
internal ArrayList HelperGetContainersSelectableItems(AutomationElement selectionContainer)
{
ArrayList list = new ArrayList();
// Win32 radio buttons do not have containers, so bail.
if (selectionContainer != null)
{
PropertyCondition pc = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true);
foreach (AutomationElement element in selectionContainer.FindAll(TreeScope.Subtree, pc))
{
// Don't want to include any "Previous" in calendar controls
if (element.Current.AutomationId.IndexOf("Previous") == -1 && element.Current.AutomationId.IndexOf("Next") == -1)
{
list.Add(element);
}
}
}
return list;
}
示例14: UIA_SetFocusOfFirstTextBox
//**************************************************************************************************************************************************************
public static void UIA_SetFocusOfFirstTextBox(AutomationElement uiaWindow, Window window)
{
try
{
PropertyCondition textCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text);
AutomationElementCollection textBoxes = uiaWindow.FindAll(TreeScope.Descendants, textCondition);
foreach (AutomationElement textBox in textBoxes)
{
TestStack.White.UIItems.TextBox t = new TestStack.White.UIItems.TextBox(textBox, window.ActionListener);
t.Focus();
t.Click();
Thread.Sleep(int.Parse(Execution_Speed));
break;
}
}
catch (Exception e)
{
String sMessage = e.Message;
LastException.SetLastError(sMessage);
throw new Exception(sMessage);
}
}
示例15: UIA_GetChildWindow
//**************************************************************************************************************************************************************
public static AutomationElement UIA_GetChildWindow(AutomationElement appWindow, string childWindowName)
{
AutomationElement childWindow = null;
try
{
PropertyCondition windowTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
PropertyCondition windowNameCondition = new PropertyCondition(AutomationElement.NameProperty, childWindowName);
AndCondition windowCondition = new AndCondition(windowTypeCondition, windowNameCondition);
AutomationElement window = appWindow.FindFirst(TreeScope.Children, windowCondition);
AutomationElementCollection windows = appWindow.FindAll(TreeScope.Descendants, windowTypeCondition);
foreach (AutomationElement w in windows)
{
if (w.Current.Name.Equals(childWindowName) || w.Current.Name.Contains(childWindowName))
{
childWindow = w;
break;
}
}
return childWindow;
}
catch (Exception e)
{
String sMessage = e.Message;
LastException.SetLastError(sMessage);
throw new Exception(sMessage);
}
}