【问题标题】:How to click on Cortana search using coded UI如何使用编码的 UI 点击 Cortana 搜索
【发布时间】:2025-12-26 22:35:12
【问题描述】:

我尝试使用 Coded UI 在 Windows 10 上单击这段代码来单击 Cortana 搜索选项:

WinPane Desktop = new WinPane();
Desktop.TechnologyName = "MSAA";
Desktop.SearchProperties.Add(WinPane.PropertyNames.ClassName, "#32769");
Desktop.SearchProperties.Add(WinPane.PropertyNames.ClassName, "Shell_TrayWnd");            
Desktop.SearchProperties.Add(WinPane.PropertyNames.ClassName, "TrayButton", WinButton.PropertyNames.ControlType, "Button");
Mouse.Click(Desktop);

有人可以建议我采用这种方法的正确方法吗?运行此测试时,它显示“无法识别隐藏控件”。

【问题讨论】:

标签: c# coded-ui-tests testautomationfx


【解决方案1】:

试试

Mouse.Click(Desktop.ToPoint())

ToPoint() 在哪里

public static Point ToPoint(this UITestControl control)
{
    var point = new Point(control.BoundingRectangle.X + control.BoundingRectangle.Width / 2,
        control.BoundingRectangle.Y + control.BoundingRectangle.Height / 2);
    return point;
}

【讨论】: