在没有 InvokePattern 或 clickablePoint 的情况下使用 UI 自动化调用单击按钮 [英] Invoke on click on a button using UI Automation with no InvokePattern or clickablePoint

查看:36
本文介绍了在没有 InvokePattern 或 clickablePoint 的情况下使用 UI 自动化调用单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向(或调用)另一个应用程序中的按钮发送点击消息.

i'm try to send click message to (or invoke) a button in another application .

我使用了 UISpy.exe 并且可以找到我需要的元素.

i used UISpy.exe and could find the element which i need.

但它没有 id,没有 clickablePoint 和 Invoke 模式.

but it has no id,no clickablePoint and no Invoke pattern.

我尝试了以下代码:

var processStartInfo = new ProcessStartInfo(@"tdesktop\Program.exe");
        var proc = Process.Start(processStartInfo);
        Thread.Sleep(3000);
        AutomationElement mainWin = AutomationElement.RootElement.FindChildByProcessId(proc.Id);
        List<AutomationElement> elmList= GetChildren(mainWin);
        //MessageBox.Show(elmList.Count.ToString());
        if (elmList.Count == 7)
        {
           List<AutomationElement> menubar= GetChildren(elmList[6]);

           AutomationElement elementNode = menubar[1];
           double x = elementNode.GetClickablePoint().X;
           double y = elementNode.GetClickablePoint().Y;

           win32 w = new win32();
           w.move_left_click((UInt32)x, (UInt32)y);


        }

它在 elementNode.GetClickablePoint().X 中抛出一个异常,即自动元素没有可点击点.

it throws an exception in elementNode.GetClickablePoint().X that the Autumation Element has no clickable point.

我也尝试过 TryGetInvokePattern() 但仍然抛出 execption 它没有 InvokePattern.

i tried also TryGetInvokePattern() but still throws execption it has no InvokePattern.

我使用 VS2012 和 .net 4.5

i use VS2012 and .net 4.5

有没有办法做到这一点?

is there any way to make this?

推荐答案

菜单栏不公开 InvokePattern(请参阅菜单栏控件类型的 UI 自动化支持).但是,菜单项可以调用d(请参阅菜单项控件类型的 UI 自动化支持).

A menu bar doesn't expose the InvokePattern (see UI Automation Support for the MenuBar Control Type). However, a menu item can be Invoked (see UI Automation Support for the MenuItem Control Type).

以下代码说明了如何生成菜单项列表:

The following code illustrates how to generate a list of menu items:

AutomationElementCollection items = menubar.FindAll(
    TreeScope.Children,
    new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem));

这篇关于在没有 InvokePattern 或 clickablePoint 的情况下使用 UI 自动化调用单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆