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

浪尽此生 提交于 2019-12-06 14:39:55

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