Beispiel #1
0
        public string Find(string testXPath)
        {
            var rootElement = AutomationHelper.GetApplicationRoot(_processId);

            var constructor = _finderType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(string) }, null);
            var finder      = constructor.Invoke(new object[] { testXPath });
            var findMethod  = finder.GetType().GetMethod("FindFirst", BindingFlags.NonPublic | BindingFlags.Instance);
            var result      = (AutomationElement)findMethod.Invoke(finder, new object[] { rootElement, 15 });

            if (result == null)
            {
                return("Not found.");
            }

            StringBuilder sb = new StringBuilder();

            foreach (var property in result.GetSupportedProperties())
            {
                var value = result.GetCurrentPropertyValue(property);
                var name  = property.ProgrammaticName.Replace("AutomationElementIdentifiers.", string.Empty);
                sb.AppendLine($"{name}: {value}");
            }

            return(sb.ToString());
        }
Beispiel #2
0
        public string Parse()
        {
            var rootElement = AutomationHelper.GetApplicationRoot(_processId);

            if (rootElement == null)
            {
                throw new Exception("Failed to find process with process id: " + _processId);
            }

            var root = CreateElementRecursive(rootElement);
            var doc  = new XDocument(root);

            return(doc.ToString(SaveOptions.None));
        }