获取无法请求未缓存错误的属性或模式

发布于 2025-02-04 02:06:35 字数 1483 浏览 1 评论 0原文

我正在尝试在桌面上的特定点获得一个自动化元素的所有属性或 目前使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文