我需要从Skype UI自动化树中获取聊天对话列表。
自动化树如下所示:
因此,在上面的自动化ui树中,以“节点”结尾的树节点是对话以及一些系统消息/文本。我需要得到这些的清单。
“我的代码”以提取对话列表:
AutomationElement parentAutomationElement= AutomationElement.FromHandle(skypeHandle);
var firstChild = TreeWalker.ControlViewWalker.GetFirstChild(parentAutomationElement); //AE of node -> "Skype Preview"
var firstGrandChild = TreeWalker.ControlViewWalker.GetFirstChild(firstChild); //AE of first child of above node. (3rd node in picture)
//info : the reason behind to extract the firstGrandChild was to be able to query the children of long automation element list.
//querying descendent from the first or second node is time consuming as each node can further have sub elements.
var chats = firstGrandChild.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "pane"));
其中一个聊天对话的自动化元素属性:
现在的问题是,提取这些对话通常需要2-4秒。会话列表计数范围是1到90(根据观察)。
我有一个计时器,可以在5秒的间隔内提取这些对话列表,我希望能够将计时器减少到2-3秒,以便经常监视对话的变化,但是我必须能够在1秒内提取对话列表。
问题:
提取上一条对话消息的代码:
var expressionAe = firstGrandChild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Open Expression picker"));
var lastChatAe = TreeWalker.ControlViewWalker.GetPreviousSibling(expressionAe);
var lastChatText = lastChatAe.Current.Name;