C#通过UI Automation 获取QQ聊天窗口的聊天记录

如图所示,通过inspect.exe可以找的到QQ聊天记录,

1:聊天窗口消息区,AutomationElement的Name值为“消息”;
2:此处是聊天记录内容。
C#程序中可找到外层聊天窗口的AutomationElement对象,但通过该对象找不到消息区


AutomationElement aeTop = AutomationElement.RootElement; //找到桌面根元素
AutomationElement aeForm = aeTop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "XXXX交流群")); //找到XXXX交流群的聊天窗口
AutomationElement aeMessage= aeForm .FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "消息")); //找不到消息区,aeMessage值为空


通过AutomationElement的两个静态方法(1.通过指定点找到AutomationElement;2.通过当前获得焦点找到AutomationElement)也不能获取到消息区的AutomationElement对象,结果获得了聊天窗口的AutomationElement对象
注:两个方法的指定点和当前焦点都已经指向消息区位置了。


AutomationElement focusedElement = AutomationElement.FocusedElement; //获取当前焦点AutomationElement元素
AutomationElement pointElement= AutomationElement.FromPoint(new System.Windows.Point(868, 346)); //获取指定点处AutomationElement元素

 来自于:C#通过UI Automation 获取QQ聊天窗口的聊天记录的疑问-CSDN社区

posted @ 2021-12-29 11:18  青山下  阅读(1414)  评论(0编辑  收藏  举报