赞
踩
1. 找到打开的微信
AutomationElement wecath = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "WeChatMainWndForPC"));
2. 找到节点的方法
AutomationElement FindNode(AutomationElement element,string name)
{
var list = element.FindAll(TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
if (list == null) return null;
foreach (System.Windows.Automation.AutomationElement item in list)
{
if (item.Current.Name == name)
{
return item;
}
else if (item.Current.Name == name)
{
return item;
}
else
{
var result = FindNode(item, name);
if (result != null) return result;
}
}
return null;
}
3. 找到左边最近聊天的节点
var result= FindNode(wecath, "会话"); // 会话 消息
MessageNode(message);
4. 找到打开的对话窗口节点
var message = FindNode(wecath, "消息");
5. 打印消息
void PrintMessage(AutomationElement element,string name="")
{
var list = element.FindAll(TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
if (list == null) return;
foreach (System.Windows.Automation.AutomationElement item in list)
{
Console.WriteLine(name + "Name:" + item.Current.Name + " ClassName=" + item.Current.ClassName + " 类型:" + item.Current.LocalizedControlType + $"{item.Current.BoundingRectangle.Location} {item.Current.AutomationId}");
// PrintMessage(item, name + " ");
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。