CodedUi: mouse click with coordinates

How to press a specific part of a button in all types of screens? I have a button with dropdown values, I need to click on the downarrow image, I tried below code:

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

      

This works on my screen, this will click somewhere else on desktops from the moment the axis is changed. Suggest some workarounds or solutions.

+3


source to share


3 answers


Try to specify a position relative to the selected control rather than an absolute point, use this property:

 uitestcontrol.BoundingRectangle

      

like this:

var btnPosition= someBtn.BoundingRectangle

      



and then select the position you want to click based on the current position of the controls.

eg:

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

      

+5


source


thanks for everything related to fixing a similar issue I ran into and struck out for two days ... My search was this: "How to click on a cell with hidden grid properties in a Windows application via CodedUI Automation"

My Sol goes like below .. credits @ Link to MSDN link



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;
                }

            }

        }

      

0


source


I had this problem and found the exact same solution as Niels in the comments above. If you do the same, what you are actually doing ignores the UI elements and you click on a known point on the screen. Your window must not move for this to work. So the solution Niels and I used could be done in 1 line of code (no need for a Bounding rectangle or someBtn) like this ...

Mouse.Click (new point (575, 920));

The risk is that your window moves, but since the coded UI has an imperceptible dot, for some reason I don't see any other way. This line is in a method in my UIMap.cs (by moving the method there by right clicking on the method in UIMap.uitest and choosing "Move Code to UIMap.cs"). So I agree with Niels, but if you do, the rest of the code in this answer won't be used!

If you don't know about moving the code in UIMap.cs then read about it, basically if you change the generated generated code without moving it then your code will be overwritten when you build the following code, leaving you wondering where you went your code and why your test stops working. Don't ask me how I know this!

0


source







All Articles