给定一个自动化元素我如何模拟它的单击左键
AutomationElement child = walker.GetFirstChild(el);
使用Windows自动化如何模拟左键单击Child?
尝试:
AutomationElement child = walker.GetFirstChild(el); System.Windows.Point p = child.GetClickablePoint(); Mouse.Move((int)pX, (int)pY); Mouse.Click(MouseButton.Left);
链接:
AutomationElement.GetClickablePoint方法
在没有真正使用鼠标的情况下模拟鼠标在WPF控件上输入/ Move / Leave
编辑评论
看到这个链接:
Mouse.cs
NativeMethods.cs
TestApi简介 – 第1部分:输入注入API
您可以通过InvokePattern
Invoke
它,而不是发送鼠标事件,如下所示:
public void InvokeAutomationElement(AutomationElement automationElement) { var invokePattern = automationElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern.Invoke(); }
如果控件具有“ClickablePoint”,则可以使用此代码
System.Windows.Point p = theButton.GetClickablePoint(); AutoItX3Lib.AutoItX3Class au3; au3 = new AutoItX3Lib.AutoItX3Class(); au3.AutoItSetOption("MouseCoordMode", 0); au3.MouseClick("LEFT", (int)pX, (int)pY, 1, -1);
其中AutoItX3Lib是AutoIt的C#API