Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CodedUi:使用坐标单击鼠标_C#_Coded Ui Tests - Fatal编程技术网

C# CodedUi:使用坐标单击鼠标

C# CodedUi:使用坐标单击鼠标,c#,coded-ui-tests,C#,Coded Ui Tests,如何在所有屏幕类型中单击按钮的特定部分?我有一个带有下拉值的按钮,我需要单击向下箭头图像,我尝试了以下代码: Mouse.click(someBtn,new Point(250,45)); 这在我的屏幕上起作用,自从axis改变后,它在桌面上的其他地方点击。建议一些变通方法或解决方案。尝试给出相对于正在单击的控件的位置,而不是绝对点, 使用此属性: uitestcontrol.BoundingRectangle 像这样: var btnPosition= someBtn.Bounding

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

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

这在我的屏幕上起作用,自从axis改变后,它在桌面上的其他地方点击。建议一些变通方法或解决方案。

尝试给出相对于正在单击的控件的位置,而不是绝对点, 使用此属性:

 uitestcontrol.BoundingRectangle
像这样:

var btnPosition= someBtn.BoundingRectangle
然后根据控件的当前位置选择要单击的位置

例如:

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

感谢所有关于解决我所面临的类似问题的线索,并取消了两天。。。我的搜索是如何通过CodedUI Automation在Windows应用程序中单击具有网格隐藏属性的单元格

我的信如下,。。信用@

public void实例化控件()
{
#区域用户搜索
frSearchUsers=new ControlWithContainer(this.SourceControl,By.ControlName(“frSearchUsers”));
txtFindUser=newcontrolwithcontainer(this.SourceControl,By.ControlName(“txtFindUser”);
vgrdUsers=newControlWithContainer(frSearchUsers.Control.SourceControl,By.ControlName(“vgrdUsers”);
vgrdUserscUSTOM=新的ControlWithContainer(vgrdUsers.Control.SourceControl,By.ControlName(“vgrdUsers”);
#端区
}
公共无效clickCell()
{
var cellGrid=vgrdUserscUSTOM.Control.SourceControl;
UITestControl cellGridCell=新UITestControl(cellGrid);
cellGridCell.SearchProperties[“ControlType”]=“Cell”;
SearchProperties[“InnerText”]=“Dawson,Jade”;
if(cellGridCell.TryFind())
{
cellGridCell.SetFocus();
cellGridCell.Find();
UITestControlCollection uic=cellGridCell.FindMatchingControls();
foreach(uic中的UITestControl ui)
{
如果(ui.BoundingRectangle.Width>0)
{
鼠标点击(ui);
打破
}
}
}

我遇到了这个问题,我在上面的评论中找到了与Niels相同的解决方案。但是,如果你也这样做,那么你实际做的是忽略UI元素,并单击屏幕上的某个已知点。你的窗口不能移动,这样才能工作。因此Niels和我使用的解决方案可以在一行代码中完成(不需要边界矩形或其他东西)像这样

鼠标点击(新点(575920))

风险在于您的窗口会移动,但由于某种原因,编码的UI有一个不可点击的点,我看不到任何其他方式。此行位于我的UIMap.cs中的一个方法中(通过右键单击UIMap.UI测试中的方法并选择“将代码移动到UIMap.cs”,将该方法移动到该方法中).所以我同意Niels的观点,但如果你这么做,答案中的其他代码就不会被使用了


如果您不知道如何将代码移动到UIMap.cs,请阅读相关内容,基本上,如果您在不移动的情况下更改系统生成的代码,那么在下一步构建时,您的代码将被覆盖,让您想知道您的代码去了哪里,以及为什么您的测试停止工作。不要问我是如何知道的!

您可以单击图像本身吗?@ErwinRooijakkers:它没有图像。没有特定的ID或其他东西。是的,甚至我也想过这样做。谢谢。我不得不删除someBtn,但我的点击变成:鼠标。点击(相对点)鼠标。点击()OP使用的重载已经取得了一个相对点,但是如果您指定了一个超出控制范围的点,或者可能在一个不可点击的点上,它似乎有一些未定义的魔法可以改变它。在这个答案中使用绝对
Click()
重载可以保证点击的点是您想要的。
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;
                }

            }

        }