【问题标题】:AutomationElement does not retrieve unvisible elementsAutomationElement 不检索不可见元素
【发布时间】:2017-08-10 19:53:24
【问题描述】:

我正在尝试获取 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)。但是,如果在我的 Skype 上打开了与 Dan 的聊天,那么 items 属性也将包含与 Dan 聊天的内部细节。 即使未在我的 Skype 中打开选项卡,我也希望 items 属性具有聊天内部详细信息。

为什么我的代码没有检索到所有数据?如何获取所有数据(包括所有聊天标签,即使它们未打开)?

【问题讨论】:

标签: c# automation ui-automation


【解决方案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);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    相关资源
    最近更新 更多