获取无法请求未缓存错误的属性或模式
我正在尝试在桌面上的特定点获得一个自动化元素的所有属性或 目前使用UI自动化C#API具有鼠标焦点。为此,我使用getPhysicalCursorPos(OUT PT)来获取所选元素的坐标和自动化元素方法的坐标来检索桌面上指定点的UI项目的新自动化对象。但是,我会遇到错误,因为该元素的每个属性“无法请求未缓存的属性或模式”。我正在使用计算器尝试。
这是测试代码...
public static void GetElements(System.Drawing.Point pt)
{
CachePropertiesWithScope(AutomationElement.RootElement);
AutomationElement ae = ElementFromCursor(pt);
}
private static void CachePropertiesWithScope(AutomationElement elementMain)
{
AutomationElement elementList = null;
CacheRequest c = new CacheRequest();
c.Add(AutomationElement.NameProperty);
c.Add(AutomationElement.IsEnabledProperty);
c.Add(SelectionItemPattern.Pattern);
c.Add(SelectionItemPattern.SelectionContainerProperty);
c.TreeScope = TreeScope.Element | TreeScope.Children;
using (c.Activate())
{
elementList =
elementMain.FindFirst(
TreeScope.Children, new PropertyCondition(
AutomationElement.NameProperty, "Calculator"));
}
}
private static AutomationElement ElementFromCursor(System.Drawing.Point pt)
{
AutomationElement element = null;
// Convert mouse position from System.Drawing.Point to System.Windows.Point.
System.Windows.Point point = new System.Windows.Point(pt.X, pt.Y);
element = AutomationElement.FromPoint(point);
return element;
}`
关于我在这里可能缺少的事情或我在做错什么的想法?
I'm trying to get all properties of an automation element present at specific point on desktop or
which currently have mouse focus using UI Automation C# API. For this, I am using GetPhysicalCursorPos(out pt) to get the co-ordinates for selected element and FromPoint method of AutomationElement to retrieves a new AutomationElement object for the UI item at specified point on the desktop. But , I am getting error as "Cannot request a property or pattern that is not cached" for each property of that element. I am trying this with Calculator.
Here is the test code...
public static void GetElements(System.Drawing.Point pt)
{
CachePropertiesWithScope(AutomationElement.RootElement);
AutomationElement ae = ElementFromCursor(pt);
}
private static void CachePropertiesWithScope(AutomationElement elementMain)
{
AutomationElement elementList = null;
CacheRequest c = new CacheRequest();
c.Add(AutomationElement.NameProperty);
c.Add(AutomationElement.IsEnabledProperty);
c.Add(SelectionItemPattern.Pattern);
c.Add(SelectionItemPattern.SelectionContainerProperty);
c.TreeScope = TreeScope.Element | TreeScope.Children;
using (c.Activate())
{
elementList =
elementMain.FindFirst(
TreeScope.Children, new PropertyCondition(
AutomationElement.NameProperty, "Calculator"));
}
}
private static AutomationElement ElementFromCursor(System.Drawing.Point pt)
{
AutomationElement element = null;
// Convert mouse position from System.Drawing.Point to System.Windows.Point.
System.Windows.Point point = new System.Windows.Point(pt.X, pt.Y);
element = AutomationElement.FromPoint(point);
return element;
}`
Any thoughts on what I may be missing here or what I am doing wrong??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论