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;
}
}