Given an Automation Element how do i simulate a si

2019-02-12 03:08发布

AutomationElement child = walker.GetFirstChild(el);

using windows automation How do i simulator a left single click on Child ?

标签: c# automation
3条回答
虎瘦雄心在
2楼-- · 2019-02-12 03:20

Rather than sending mouse events, you can Invoke it through the InvokePattern like so:

public void InvokeAutomationElement(AutomationElement automationElement)
{
    var invokePattern = automationElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
    invokePattern.Invoke();
}
查看更多
够拽才男人
3楼-- · 2019-02-12 03:40

try with:

AutomationElement child = walker.GetFirstChild(el);
System.Windows.Point p = child.GetClickablePoint();
Mouse.Move((int)p.X, (int)p.Y);
Mouse.Click(MouseButton.Left);

Links:
AutomationElement.GetClickablePoint Method
Simulate mouse Enter/Move/Leave on WPF control without real mouse usage

Edit for comment

See this links:

Mouse.cs
NativeMethods.cs
Introduction to TestApi – Part 1: Input Injection APIs

查看更多
干净又极端
4楼-- · 2019-02-12 03:44

if the control has a "ClickablePoint" you can use this code

            System.Windows.Point p = theButton.GetClickablePoint();
            AutoItX3Lib.AutoItX3Class au3;
            au3 = new AutoItX3Lib.AutoItX3Class();
            au3.AutoItSetOption("MouseCoordMode", 0);
            au3.MouseClick("LEFT", (int)p.X, (int)p.Y, 1, -1);

where AutoItX3Lib is the C# API for AutoIt

查看更多
登录 后发表回答