我正在尝试获取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聊天的内部细节。 我希望items属性具有聊天内部细节,即使我的Skype中没有打开选项卡。
为什么我的代码无法检索所有数据?我怎样才能获得所有数据(包括所有聊天标签,即使它们没有打开)?
答案 0 :(得分:0)
迭代所有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);
}