How to click on a “pane” using UI automation library?

守給你的承諾、 提交于 2019-12-08 06:01:48

问题


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();

Is there any other way to do it?


回答1:


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.

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());


来源:https://stackoverflow.com/questions/12662426/how-to-click-on-a-pane-using-ui-automation-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!