How to manipulate a control without any pattern implemented?

天涯浪子 提交于 2019-12-06 08:28:44

The only way to interact when Control Patterns are not implemented is to go clicking around stuff. I would suggest try following to avoid maximum errors.

  1. Before sending the click, make sure the parent of button(pane or window is set to foreground)
  2. Instead of sending the click to corner of the AutomationElement, try sending it in midpoint, of the element,
  3. Also, try hovering over the element first, the wait like 200ms, and then send click, So that you are sure to see execution.[Trust me, this helps debugging a lot and avoids many issues.]

The best thing would be, if those guys who implement the system would implement server-side UIA provider to their UI Elements!

But often that's not possible..., I used the following workaround (at least for clicking/toggling):

AutomationElement yourAE = ...// some code to find the right AutomationElement (AE)
clickablePoint = yourAE.GetClickablePoint();

also BoundingRectangleProperty could be of help

If you receive that clickable point you can use

System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);

to move to the location, and than click it via InputSimulator or some win32 (user32.dll) commands. (note: of course you can also use InputSimulator or win32 to move the mouse - but I had some problems with the InputSimulator when it came to several screens with different locations or resolutions - so Cursor.Position was the easiest approach, which is also very reliable)


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