如何点击“窗格"使用UI自动化库? [英] How to click on a "pane" using UI automation library?

查看:97
本文介绍了如何点击“窗格"使用UI自动化库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个需要在其中单击窗格的应用程序.我尝试使用下面的代码,该代码用于单击按钮,但它给出了不受支持的模式异常.

We have an application in which I need to click on a Pane. I tried to use the following code, which I use to click on a button, but it gave Unsupported pattern exception.

InvokePattern click_pattern = (InvokePattern)adjust_button.GetCurrentPattern(InvokePattern.Pattern); click_pattern.Invoke();

InvokePattern click_pattern = (InvokePattern)adjust_button.GetCurrentPattern(InvokePattern.Pattern); click_pattern.Invoke();

还有其他方法吗?

推荐答案

即使对象是可单击的,但根据内部对单击的处理方式,您不一定可以使用InvokePattern来执行单击.似乎是这种情况.

Even though the object is clickable, depending on how the click is being handled internally, you may not necessarily be able to use the InvokePattern to perform a click. That appears to be the case here.

作为替代,您可以使用一些代码将鼠标光标移到窗格上,并使用P/Invoke发出单击.像这样:

As an alternative, you can use some code to move the mouse cursor over the pane and issue a click using P/Invoke. Something like this:

private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;

[DllImport("user32.dll")]
private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);

...
...

AutomationElement paneToClick;

...
...

Cursor.Position = paneToClick.GetClickablePoint();
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new IntPtr());
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new IntPtr());

这篇关于如何点击“窗格"使用UI自动化库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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