Question

When I am trying to preform a mouse.Click() on a certain point inside a viewer I get the following error.

The code first:

public void ClickOnViewerSpace(int addX = 0, int addY = 0) {            
        //Mouse.Click(new Point(2439 + addX, 560 + addY));
        int x = _contentContainer.BoundingRectangle.Location.X;
        int y = _contentContainer.BoundingRectangle.Location.Y;
        Mouse.Click(new Point(x + addX, y + addY));
}

The error:

Test Name: TC1_9_2_AdminEnter Test FullName: Test Source: line 427 Test Outcome: Failed Test Duration: 0:00:31.5364285

Result Message: Test method threw exception: Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException: Cannot perform 'Click' on the control. Additional Details: The control details were not specified. ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component. Result StackTrace: at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.MouseButtonClick(Int32 x, Int32 y, Int32 nButton, Int32 fEnsureVisible, String bstrKeyModifiers) at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.MouseButtonClick(Int32 x, Int32 y, MouseButtons button, ModifierKeys modifierKeys, Int32 ensureVisible) at Microsoft.VisualStudio.TestTools.UITesting.UITestActionExecutorCore.Click(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate) --- End of inner exception stack trace --- at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context) at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(SystemException exception, IPlaybackContext context) at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(SystemException exception, String actionName, UITestControl uiControl) at Microsoft.VisualStudio.TestTools.UITesting.UITestActionExecutorCore.Click(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate) at Microsoft.VisualStudio.TestTools.UITesting.Mouse.ClickImplementation(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate) at Microsoft.VisualStudio.TestTools.UITesting.Mouse.<>c__DisplayClass6.b__5() at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction) at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate) at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(Point screenCoordinate) at ObjectsRepository.TouchViewer.ClickOnViewerSpace(Int32 addX, Int32 addY) in d:\test\auto\ObjectsRepository\TouchViewer.cs:line 109

Was it helpful?

Solution

It seems that even though the Mouse.Click(Point) method exists, the CUIT framework does not allow a click action without a UITestControl. Here is a good link to follow: Mouse.Click using Point only

The stack trace looks like it aligns with this since every method after the initial Mouse.Click(Point) call depends on a UITestControl.

Based on the code posted, I would try something like this:

public void ClickOnViewerSpace(int addX = 0, int addY = 0)
{
    //int x = _contentContainer.BoundingRectangle.Location.X;
    //int y = _contentContainer.BoundingRectangle.Location.Y;
    //Mouse.Click(new Point(x + addX, y + addY));
    Mouse.Click(_contentContainer, new Point(addX, addY)); // relative coords
}

OTHER TIPS

Another option is to add _contentContainer.Find() before generating coordinates based on this control.

thanks for all the lead on fixing the similar issue which i faced & struck out for two days ... My Search was How to Click on cell with hidden properties of a Grid in Windows application through CodedUI Automation

My Sol goes as below ,.. credits @ 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;
                }

            }

        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top