I have to find all the controls in a specific url and print the name property of those controls.
[TestMethod]
public void CodedUITestMethod1()
{
Console.WriteLine("inside method1");
BrowserWindow browser = BrowserWindow.Launch(new Uri("https://technet.microsoft.com/en-us/"));
browser.Maximized = true;
Playback.Wait(10000);
PropertyCondition autoid =new PropertyCondition(AutomationElement.AutomationIdProperty, "megabladeMainMenu");
AutomationElement control = AutomationElement.RootElement.FindFirst(TreeScope.Subtree, autoid);
Properties(control);
}
private void Properties(AutomationElement element)
{
Console.WriteLine("inside method2");
if (element == null)
{
Console.WriteLine("null");
return;
}
AutomationElement elementNode = TreeWalker.ControlViewWalker.GetFirstChild(element);
while (elementNode != null)
{
string controlName = (elementNode.Current.Name == "") ? "Unnamed Control" : elementNode.Current.Name;
string autoIdName = (elementNode.Current.AutomationId == "") ? "No AutomationID" : elementNode.Current.AutomationId;
Console.WriteLine("Name Property : " + controlName);
Console.WriteLine("automation Id : " + autoIdName);
}
elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode);
Properties(elementNode);
}
Tried it this way but the automation element being passed is recognized as null.Can I get any suggestions regarding this problem.