A
Adinb007
Guest
Folks,
I need to to click on "Open" button however this control is not available through UIAutomation approach.
Below is the code.
public bool PressButton(string parentclassname, string windowTitle, string buttonClassName,string buttonName)
{
windowTitle = windowTitle.ToLower();
bool result = false;
try
{
IntPtr parentHandle = FindWindow(parentclassname, windowTitle);
var parentElements = AutomationElement.FromHandle(parentHandle).FindAll(TreeScope.Children, Condition.TrueCondition);
foreach (AutomationElement parentElement in parentElements)
{
if (parentElement.Current.ClassName !="")
{
var childElements = parentElement.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach (AutomationElement childElement in childElements)
{
if(childElement.Current.ClassName == "Button")
{
AutomationElement aeButton = childElement.FindFirst(System.Windows.Automation.TreeScope.Element, new System.Windows.Automation.PropertyCondition(System.Windows.Automation.AutomationElement.NameProperty, childElement.Current.Name));
if (aeButton != null)
{
try
{
InvokePattern vpattern = (InvokePattern)aeButton.GetCurrentPattern(InvokePattern.Pattern);
if (vpattern != null)
{
System.Threading.Thread.Sleep(1000);
vpattern.Invoke();
result = true;
//break;
}
}
catch
{
result = false;
continue;
}
}
}
if (result)
{
break;
}
}
}
}
catch (Exception ex)
{
result = false;
}
return result;
}
Aditya Sharma
Continue reading...
I need to to click on "Open" button however this control is not available through UIAutomation approach.
Below is the code.
public bool PressButton(string parentclassname, string windowTitle, string buttonClassName,string buttonName)
{
windowTitle = windowTitle.ToLower();
bool result = false;
try
{
IntPtr parentHandle = FindWindow(parentclassname, windowTitle);
var parentElements = AutomationElement.FromHandle(parentHandle).FindAll(TreeScope.Children, Condition.TrueCondition);
foreach (AutomationElement parentElement in parentElements)
{
if (parentElement.Current.ClassName !="")
{
var childElements = parentElement.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach (AutomationElement childElement in childElements)
{
if(childElement.Current.ClassName == "Button")
{
AutomationElement aeButton = childElement.FindFirst(System.Windows.Automation.TreeScope.Element, new System.Windows.Automation.PropertyCondition(System.Windows.Automation.AutomationElement.NameProperty, childElement.Current.Name));
if (aeButton != null)
{
try
{
InvokePattern vpattern = (InvokePattern)aeButton.GetCurrentPattern(InvokePattern.Pattern);
if (vpattern != null)
{
System.Threading.Thread.Sleep(1000);
vpattern.Invoke();
result = true;
//break;
}
}
catch
{
result = false;
continue;
}
}
}
if (result)
{
break;
}
}
}
}
catch (Exception ex)
{
result = false;
}
return result;
}
Aditya Sharma
Continue reading...