辅助功能测试自动化

时间:2016-11-04 11:18:41

标签: c# visual-studio coded-ui-tests

我必须找到特定网址中的所有控件并打印这些控件的name属性。

通过以下方式尝试,但传递的自动化元素被识别为null。我可以得到有关此问题的任何建议。

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

0 个答案:

没有答案