本文整理汇总了C#中System.Windows.Automation.AutomationElement.FindFirst方法的典型用法代码示例。如果您正苦于以下问题:C# AutomationElement.FindFirst方法的具体用法?C# AutomationElement.FindFirst怎么用?C# AutomationElement.FindFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Automation.AutomationElement
的用法示例。
在下文中一共展示了AutomationElement.FindFirst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ButtonClick
private static bool ButtonClick(AutomationElement inElement, string automationId)
{
PropertyCondition btnCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId);
Console.WriteLine("Searching for the {0} button...", automationId);
AutomationElement control = inElement.FindFirst(TreeScope.Descendants, btnCondition);
if (control != null)
{
Console.WriteLine("Clicking the {0} button", automationId);
object controlType = control.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty);
if (controlType == ControlType.Button)
{
InvokePattern clickCommand = control.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
clickCommand.Invoke();
}
else if (controlType == ControlType.RadioButton)
{
SelectionItemPattern radioCheck = control.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
radioCheck.Select();
}
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Button {0} clicked.", automationId);
return true;
}
else
{
Console.WriteLine("Could not find button {0} ", automationId);
return false;
}
}
示例2: InvokeDialogOk
private void InvokeDialogOk(Process process, AutomationElement window, string dialogClass, string okName)
{
process.WaitForInputIdle();
AutomationElement dialog = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, dialogClass));
while(dialog == null)
{
Thread.Sleep(16);
dialog = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, dialogClass));
}
AutomationElement button = dialog.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, okName));
object invoke;
if (button.TryGetCurrentPattern(InvokePattern.Pattern, out invoke))
{
((InvokePattern)invoke).Invoke();
}
}
示例3: getAutomationElement
public static AutomationElement getAutomationElement(AutomationElement parent, TreeScope scope, ControlType type, string name)
{
var element = parent.FindFirst(scope, new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, type),
new PropertyCondition(AutomationElement.NameProperty, name),
Automation.ControlViewCondition));
return element;
}
示例4: FindWindowByName
public static AutomationElement FindWindowByName(AutomationElement rootElement, string name, ControlType type)
{
PropertyCondition nameCondition = new PropertyCondition(AutomationElement.NameProperty, name);
PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);
AndCondition andCondition = new AndCondition(nameCondition, typeCondition);
return rootElement.FindFirst(TreeScope.Element | TreeScope.Descendants, andCondition);
}
示例5: FindElementById
public static AutomationElement FindElementById(AutomationElement parentElement, string automationID, ControlType type)
{
PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);
PropertyCondition IDCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationID);
AndCondition andCondition = new AndCondition(typeCondition, IDCondition);
return parentElement.FindFirst(TreeScope.Element | TreeScope.Descendants, andCondition);
}
示例6: GetElement
public AutomationElement GetElement(AutomationElement rootElement, AutomationProperty property, object value, TreeScope searchScope)
{
AutomationElement aeMainWindow = null;
int numWaits = 0;
do
{
aeMainWindow = rootElement.FindFirst(searchScope, new PropertyCondition(property, value));
++numWaits;
Thread.Sleep(200);
} while (aeMainWindow == null && numWaits < 50);
return aeMainWindow;
}
示例7: ExtractElement
/// <summary>
/// Extract Window from parent window
/// </summary>
/// <param name="parent"></param>
/// <param name="titleName"></param>
/// <returns></returns>
public static AutomationElement ExtractElement(AutomationElement parent, string nameValue, TreeScope treeScope)
{
ValidateArgumentNotNull(parent, "Extract Window from parent window");
Condition condition = new PropertyCondition(AutomationElement.NameProperty, nameValue);
AutomationElement appElement;
DateTime timeOut = DateTime.Now.AddMilliseconds(TimeOutMillSec);
do
{
appElement = parent.FindFirst(treeScope, condition);
} while (appElement == null && DateTime.Now < timeOut);
return appElement;
}
示例8: Window
public Window(IntPtr hWnd)
: base(hWnd)
{
Angle = 0;
Scale = 1;
hasMenu = false;
Contacts = new WindowContacts(this);
automationElement = AutomationElement.FromHandle(hWnd);
PropertyCondition condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuBar);
AutomationElement first = automationElement.FindFirst(TreeScope.Descendants, condition);
if (first != null && !first.Current.Name.Equals("System Menu Bar"))
hasMenu = true;
}
示例9: GetElement
/// <summary>
/// This method returns an element searched by its control type from the tree.
/// </summary>
/// <param name="root">Root Element of the control</param>
/// <param name="controlType">Control Type of the element</param>
/// <returns>Automation Element of teh control</returns>
public static AutomationElement GetElement(AutomationElement root, ControlType controlType)
{
if (root == null)
{
throw new ArgumentNullException("root");
}
if (controlType == null)
{
throw new ArgumentNullException("controlType");
}
else
{
PropertyCondition condType = new PropertyCondition(AutomationElement.ControlTypeProperty, controlType);
return root.FindFirst(TreeScope.Descendants, condType);
}
}
示例10: AutomationElementFromCustomId
public const int TIMEWAIT = 100; // Used for starting process
#endregion
#region AutomationElementFromCustomId
// -------------------------------------------------------------------
// Finds an automation element from a given Automation ID
// -------------------------------------------------------------------
static public AutomationElement AutomationElementFromCustomId(AutomationElement element, object identifier, bool verbose)
{
Library.ValidateArgumentNonNull(element, "Automation Element");
Library.ValidateArgumentNonNull(identifier, "Automation ID");
if (verbose == true)
/* changing to new flexible logging */
//Logger.LogComment("Looking for control (" + identifier + ")");
UIVerifyLogger.LogComment("Looking for control (" + identifier + ")");
AutomationElement ae;
ae = element.FindFirst(TreeScope.Children | TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, identifier));
if (ae == null)
{
throw new ArgumentException("Could not identify the element based on the AutomationIdProperty");
}
return ae;
}
示例11: WaitForElementByName
public static AutomationElement WaitForElementByName(AutomationElement element, int seconds, AutomationElement parent, string name)
{
while (element == null)
{
Thread.Sleep(1000);
seconds--;
element = parent.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, name));
if (seconds == 0)
{
throw new NoSuchElementException("Can't find element or it's not loaded!");
}
}
return element;
}
示例12: FindBy
static AutomationElement FindBy(AutomationElement root, int wait, PropertyCondition condition)
{
var waitCount = 0;
AutomationElement node;
do
{
node = root.FindFirst(
TreeScope.Descendants,
condition);
if(node == null && waitCount <= wait)
Thread.Sleep(ImplicitWaitInterval);
waitCount++;
} while (node == null && waitCount <= wait);
return node;
}
示例13: FindFirst
internal static AutomationElement FindFirst(
AutomationElement parent,
TreeScope scope,
Condition condition,
int timeout)
{
var dtn = DateTime.Now.AddMilliseconds(timeout);
// ReSharper disable once LoopVariableIsNeverChangedInsideLoop
while (DateTime.Now <= dtn)
{
var element = parent.FindFirst(scope, condition);
if (element != null)
{
return element;
}
}
return null;
}
示例14: InvokeMenuItem
private void InvokeMenuItem(Process process, AutomationElement window, string menu, string menuItem)
{
AutomationElement menuElement = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menu));
object menuExpand;
if (menuElement.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out menuExpand))
{
((ExpandCollapsePattern)menuExpand).Expand();
process.WaitForInputIdle();
AutomationElement menuItemElement = menuElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menuItem));
while (menuItemElement == null)
{
Thread.Sleep(16);
menuItemElement = menuElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menuItem));
}
object menuItemInvoke;
if (menuItemElement.TryGetCurrentPattern(InvokePattern.Pattern, out menuItemInvoke))
{
((InvokePattern)menuItemInvoke).Invoke();
}
}
}
示例15: OvertimeWindowApproachingCancel
public static bool OvertimeWindowApproachingCancel(AutomationElement parent)
{
if (parent == null)
return false;
var cancel = parent.FindFirst(TreeScope.Descendants,
new System.Windows.Automation.PropertyCondition(
AutomationElement.AutomationIdProperty, "_CancelButton"));
object pattern;
if (cancel.TryGetCurrentPattern(InvokePattern.Pattern, out pattern))
{
var buttonPattern = pattern as InvokePattern;
if (buttonPattern != null)
{
buttonPattern.Invoke();
return true;
}
}
return false;
}