Esempio n. 1
0
        public void Find_Button1_ByName_Find_Anywhere()
        {
            //Arrange
            string            ElementName             = "button1";
            string            ExpectedElementFullPath = "/[AutomationId:tableLayoutPanel1]/[AutomationId:tableLayoutPanel2]/button1";
            string            Button1Xpath            = "button1"; // Simple control with name on the root, validate XPath that doesn't start with /
            PropertyCondition cond    = new PropertyCondition(AutomationElementIdentifiers.NameProperty, ElementName);
            AutomationElement button1 = AppWindow.FindFirst(TreeScope.Descendants, cond);
            //Act

            string AbsoluteXPath = UIA.GetElementAbsoluteXPath(button1);

            AutomationElement AEButton       = UIA.GetElementByXpath(Button1Xpath);
            string            AbsoluteXPath2 = UIA.GetElementAbsoluteXPath(AEButton);
            UIAElementInfo    EI             = new UIAElementInfo()
            {
                ElementObject = AEButton, WindowExplorer = UIA.WindowExplorer
            };
            string SmartXPath = mXPathHelper.GetElementXpathSmart(EI);

            //Assert
            Assert.AreEqual(ExpectedElementFullPath, AbsoluteXPath, "ExpectedElementFullPath=AbsoluteXPath");
            Assert.AreEqual(button1, AEButton, "button1=AEButton");
            Assert.AreEqual(SmartXPath, "button1[AutomationId:button1][LocalizedControlType:button1]", "SmartXPath");  // We expect the smart XPath to find the name is unique
        }