AutomationElement无法检索不可见元素

4

我正在尝试获取Skype程序中的所有元素(包括所有聊天选项卡),但我只得到可见的项目。

这是代码:

var window = AutomationElement.RootElement.FindFirst(TreeScope.Subtree,
                new PropertyCondition(AutomationElement.ClassNameProperty, "tSkMainForm"));

if (window != null)
{
    var items = window.FindAll(TreeScope.Subtree, Condition.TrueCondition);
    //DO SOME CODE...
}

items属性不包含所有隐藏的项目(例如与某人的聊天的内部细节,比如说Dan)。但如果与Dan的聊天在我的Skype中打开,则items属性还将包含此聊天与Dan的内部细节。

我希望即使选项卡在我的Skype中未打开,items属性也能具有聊天内部细节。

为什么我的代码无法检索所有数据?如何获取所有数据(包括所有聊天选项卡,即使它们没有打开)?


2
当您使用标准的UIA工具“inspect.exe”(https://msdn.microsoft.com/en-us/library/windows/desktop/dd318521.aspx)时,您可以看到元素吗? - Simon Mourier
1个回答

1
遍历所有GridControl行时,使用GridControlAutomationPeer的IScrollProvider接口实现。
private void Button_Click_1(object sender, RoutedEventArgs e) {
            var p = Process.GetProcessesByName(ProcName).FirstOrDefault(x => x != null);
            if (p == null) {
                Console.WriteLine("proccess: {0} was not found", ProcName); return;
            }
            var root = AutomationElement.RootElement.FindChildByProcessId(p.Id);
            AutomationElement devexGridAutomationElement = root.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, DevexGridAutomationId));
            if (devexGridAutomationElement == null) {
                Console.WriteLine("No AutomationElement was found with id: {0}", DevexGridAutomationId);
                return;
            }

            var cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem);
            var devexGridItems = devexGridAutomationElement.FindAll(TreeScope.Descendants, cond);
            GridPattern gridPat = devexGridAutomationElement.GetCurrentPattern(GridPattern.Pattern) as GridPattern;
            Console.WriteLine("number of elements in the grid: {0}", gridPat.Current.RowCount);
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接