Hello All,
Iam trying to find automation element for the particular component in Web apps developed using ASP.Net .I could not find al the automation elements and Ids .I could see al l the properties using UIA2.0
Please go through the below code. Appreciate your help !
uSECASE 1:
public static void getRecursiveElements(AutomationElement parent)
{
AutomationElementCollection children,children1,children2;
children = parent.FindAll(TreeScope.Descendants, Condition.TrueCondition);
if (children != null && children.Count != 0)
{
for (int i = 0; i < children.Count; i++)
{
//AutomationElement val = children[i].Current;
//getRecursiveElements(children[i]);
sw.WriteLine(children[i].Current.Name);
sw.WriteLine(children[i].Current.AutomationId);
sw.WriteLine(children[i].Current.LocalizedControlType);
//if (children[i].Current.Name == "Create/Edit Asset")
//{
children1 = children[i].FindAll(TreeScope.Descendants, Condition.TrueCondition);
if (children1 != null && children1.Count != 0)
{
for (int j = 0; j < children1.Count; j++)
{
sw.WriteLine("ChildName1----->" + children1[j].Current.Name);
sw.WriteLine("ChildID----->" + children1[j].Current.AutomationId);
sw.WriteLine(children1[j].Current.LocalizedControlType);
children2 = children1[j].FindAll(TreeScope.Descendants, Condition.TrueCondition);
if (children2 != null&&children2.Count!=0)
{
for (int k = 0; k < children2.Count; k++)
{
sw.WriteLine("ChildName2----->" + children2[k].Current.Name);
sw.WriteLine("ChildID----->" + children2[k].Current.AutomationId);
sw.WriteLine(children2[k].Current.LocalizedControlType);
}
}
}
}
// }
}
}
sw.Close();
}
useCase 2:
private AutomationElement WalkControlElements1(AutomationElement rootElement)
{
// Conditions for the basic views of the subtree (content, control, and raw)
// are available as fields of TreeWalker, and one of these is used in the
// following code.
AutomationElement elment = rootElement;
AutomationElement elementNode = null;
if (elment == null) return elementNode;
// your logic for condition ( this I don’t know what to write)
//bool val = true;
elementNode = elment.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Select Business Category Product"));
if (elementNode != null)
{
///val = true;
return elementNode;
}
WalkControlElements1(TreeWalker.ControlViewWalker.GetFirstChild(elment));
// Call for next sibling
WalkControlElements1(TreeWalker.ControlViewWalker.GetNextSibling(elment));
// Call for First child
return elementNode;
}