CodedUi:Mouse 点击坐标

CodedUi:Mouse click with coordinates

如何在所有屏幕类型中单击按钮的特定部分?我有一个带有下拉值的按钮,我需要单击向下箭头图像,我尝试了以下代码:

 Mouse.click(someBtn,new Point(250,45));

这在我的屏幕上有效,因为轴发生变化,它会在桌面上的其他地方点击。建议一些解决方法或解决方案。

尝试给出相对于被点击控件的位置,而不是绝对点, 使用这个 属性:

 uitestcontrol.BoundingRectangle

像这样:

var btnPosition= someBtn.BoundingRectangle

然后select根据控件当前位置选择要点击的位置。

例如:

Point relativePoint = new Point(btnPosition.X + 40, btnPosition.Y - 40);
Mouse.click(someBtn,relativePoint );

感谢所有领导解决我面临并解决了两天的类似问题...我的搜索是如何通过 CodedUI 在 Windows 应用程序中单击具有网格隐藏属性的单元格自动化

我的 Sol 如下所示,.. 学分 @ MSDN link dude

public void InstantiateControls()
    {

        #region  UserSearch
        frSearchUsers = new ControlWithContainer<WinGroup>(this.SourceControl, By.ControlName("frSearchUsers"));
        txtFindUser = new ControlWithContainer<WinEdit>(this.SourceControl, By.ControlName("txtFindUser"));
        vgrdUsers = new ControlWithContainer<WinWindow>(frSearchUsers.Control.SourceControl, By.ControlName("vgrdUsers"));
        vgrdUserscUSTOM = new ControlWithContainer<WinCustom>(vgrdUsers.Control.SourceControl, By.ControlName("vgrdUsers"));

        #endregion
    }

    public void clickCell()
    {
        var cellGrid = vgrdUserscUSTOM.Control.SourceControl;
        UITestControl cellGridCell = new UITestControl(cellGrid);
        cellGridCell.SearchProperties["ControlType"] = "Cell";
        cellGridCell.SearchProperties["InnerText"] = "Dawson,Jade";            
        if (cellGridCell.TryFind())
        {
            cellGridCell.SetFocus();
            cellGridCell.Find();             

            UITestControlCollection uic = cellGridCell.FindMatchingControls();

            foreach (UITestControl ui in uic)
            {
                if (ui.BoundingRectangle.Width > 0)
                {
                    Mouse.Click(ui);
                    break;
                }

            }

        }

我遇到了这个问题,我找到了与 Niels 在上面的评论中所做的相同的解决方案。但是,如果您这样做,您实际做的是忽略 UI 元素,并且您正在单击屏幕上的已知点。您的 window 不能移动才能正常工作。所以 Niels 和我自己使用的解决方案可以像这样在 1 行代码中完成(不需要边界矩形或 someBtn)...

Mouse.Click(新点(575, 920));

风险是您的 window 移动了,但由于编码 UI 有一个不可点击的点,出于某种原因我看不到任何其他方式。这一行在我的 UIMap.cs 中的一个方法中(通过右键单击 UIMap.uitest 中的方法并选择 "Move Code to UIMap.cs" 将方法移到那里)。所以我同意 Niels 的观点,但如果你这样做,该答案中的其余代码将不会被使用!

如果您不知道将代码移动到 UIMap.cs,请阅读相关内容,基本上,如果您更改系统生成的代码而不移动它,那么您的代码将在您接下来构建时被覆盖,让您想知道在哪里你的代码成功了,为什么你的测试停止工作。别问我怎么知道的!