解决方法
您可以使用
UIAComWrapper执行此操作,您将需要处理该窗口(从您尝试复制的位置)以及有关该元素的信息,您可以从
UIAutomationVerify获得.
var elementCollection = AutomationElement.FromHandle(windowHandle).FindAll(TreeScope.Subtree,Condition.TrueCondition); foreach (var item in elementCollection) { //check item properties if element is the one you looking for }
此外,您可以提供更复杂的过滤器来获取仅一个元素,而不是Condition.TrueCondition.
编辑,添加真实示例:
[DllImport("user32.dll",SetLastError = true)] public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); const string InternetExplorerClass = "IEFrame"; static void Main() { var windowHandle = new IntPtr(0); //Find internet explorer instance windowHandle = FindWindow(InternetExplorerClass,null); if (!windowHandle.Equals(IntPtr.Zero)) { //create filter to improve search speed var localizedControlType = new PropertyCondition( AutomationElement.LocalizedControlTypeProperty,"tab item"); //get all elements in internet explorer that match our filter var elementCollection = AutomationElement.FromHandle(windowHandle) .FindAll(TreeScope.Subtree,localizedControlType); //iterate through search results foreach (AutomationElement item in elementCollection) { Console.WriteLine(item.Current.Name); } } else { Console.WriteLine("Internet explorer not found"); } Console.ReadLine(); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。