locked
Mouse.Click not behaving as expected when using UITestControl as an argument

    Question

  • I am trying to have Mouse.Click click on the center of a UITestControl, but it keeps clicking on the top middle of the control.  The problem is, the conrol is 27 pixels high, and only the bottom 20 pixels or so accepts a click.  I tried doing:

    Mouse.Click(myUIControl, new Point(myUIControl.BoundingRectangle.Width /2, myUIControl.BoundingRectangle.Height /2);

    But that still kept clicking on the top middle, so I tried:

    Point myPoint = new Point(27,12);  // hard coded the math from the bounding rectangle
    Mouse.Click(myUIControl, myPoint);

    But that clicked on the top middle as well.  The only way I was able to get it to work was:

    Mouse.Click(myUIControl.BoundingRectangle.X + myUIControl.BoundingRectangle.Width / 2, myUIControl.BoundingRectangle.Y + myUIControl.BoundingRectangle.Height / 2);

    This just hardcodes an absolute X and an absolute Y into the Mouse.Click, but then I loose any inherent waits when you do Mouse.Click(UITestControl).  Shouldn't Mouse.Click(UITestControl,Point) work?  Also, I assume when Point is the second parameter in Mouse.Click, it is relative to the UITestControl, is that correct?

    Thanks,
    Micah

    Thursday, May 27, 2010 3:02 PM

Answers

  • If you want to click on that image you can try to do in the following way (without using Point object):

    - add all the objects to UIMap (in an hierarchical way, for example, for your situation: Browser.BrowserDocument...Cell). The Cell object will be the parent for the DIVs and IMG objects.  If you have just an IMG file, you can add the object and set the filter property TagName to "IMG". In this case, to select it you can use:  Browser.BrowserDocument...Cell.ImgName(the object will be identified by the search engine after the img property). To click on it, you can use Mouse.Click(Browser.BrowserDocument...Cell.IMGName - it shoudl work).

    About the DIVs, you need to find a way to identify one DIV from another, to be able to access each one of it. I don't know your structure, but you should be able to add and use the objects in a way or another; if this thing is impossible, than you can't use the automation to do that.

    If you still aren't be able to do it, please add here the HTML structure of your page and the object that need to be clicked. If the HTML is different, please add two or three example.

    • Marked as answer by MrMicah Thursday, June 17, 2010 3:55 PM
    Tuesday, June 01, 2010 10:51 PM

All replies

  • from API Reference for Testing Tools for VS

    Method Mouse.Click(UITestControl, Point)

    Clicks the default mouse button on the specified control at the specified location relative to that control.

    Thursday, May 27, 2010 3:30 PM
  • Quang To,

    Thanks for the reply, but that is what I tried, however, it still clicks the top of the control, regardless of what Point I pass in.

    -Micah

    Thursday, May 27, 2010 3:37 PM
  • I didn't mean you should try it, I just answer your question "...it is relative to the UITestControl, is that correct?" :-)

    what are inherent waits you wish? Try replacing Mouse.Click(Point) by Mouse.StartDragging(UITestControl, Point) and Mouse.StopDragging(UITestControl, Point). If control is null, point will be absolute

    Thursday, May 27, 2010 3:43 PM
  • Using Mouse.Click with a UITestControl as a parameters, has a WaitForControlReady wait inherintly associated with it (at least that is my understanding).  If I use the code that works:

    Mouse.Click(myUIControl.BoundingRectangle.X + myUIControl.BoundingRectangle.Width / 2, myUIControl.BoundingRectangle.Y + myUIControl.BoundingRectangle.Height / 2);

    Then I loose that, because I am essentially using:

    Mouse.Click(x,y);

    What I really want to know, is why isn't:

    Mouse.Click(UITestControl, Point);

    working?  The "Point" parameter is being ignored.  Incidentally, the UITestControl is of type HtmlCell.

    -Micah

    Friday, May 28, 2010 5:15 PM
  • [I assume the center of the control is visible since you have already mentioned that you are able to do a mouse click using absolute screen coordinates.]

    Can you try the following - Start the CodedUITest locator. Hover the mouse pointer at the center of the control (where you want the click to go) and do a Win+I. What is the control that the CodedUI Test is recognizing? Is it the HtmlCell or some other control inside it?

    Monday, May 31, 2010 1:33 AM
  • Inside the cell, there are a few DIVs and an IMG.  I did not want to drill down through the DIVs to get to the IMG file, since the DIVs are named at runtime and I never know any information about them.  The IMG file has a dynamic name as well.  The only thing that didn't was the HtmlCell, hence why I picked it.

    But, to answer your question, it recognizes an IMG file.

    -Micah

    • Edited by MrMicah Tuesday, June 01, 2010 6:44 PM To actually answer Tapas' question.
    Tuesday, June 01, 2010 6:43 PM
  • If you want to click on that image you can try to do in the following way (without using Point object):

    - add all the objects to UIMap (in an hierarchical way, for example, for your situation: Browser.BrowserDocument...Cell). The Cell object will be the parent for the DIVs and IMG objects.  If you have just an IMG file, you can add the object and set the filter property TagName to "IMG". In this case, to select it you can use:  Browser.BrowserDocument...Cell.ImgName(the object will be identified by the search engine after the img property). To click on it, you can use Mouse.Click(Browser.BrowserDocument...Cell.IMGName - it shoudl work).

    About the DIVs, you need to find a way to identify one DIV from another, to be able to access each one of it. I don't know your structure, but you should be able to add and use the objects in a way or another; if this thing is impossible, than you can't use the automation to do that.

    If you still aren't be able to do it, please add here the HTML structure of your page and the object that need to be clicked. If the HTML is different, please add two or three example.

    • Marked as answer by MrMicah Thursday, June 17, 2010 3:55 PM
    Tuesday, June 01, 2010 10:51 PM
  • Siliviu's proposed solution looks good. If you still want to persist using only Cell only for search and click, try if the following works for you -

    cellUITestControl.SetFocus();

    Rectangle r = cellUITestControl.BoundingRectangle;

    Mouse.Click(new Point(r.X + r.Width/2 + r.Y + r.Height/2)); 

    Wednesday, June 02, 2010 2:02 AM
  • My problem is, why isn't Mouse.Click working as it is described in the help?  I think this may need to be investigated by MSFT.  I have plenty of work arounds that do work, but why should it need a work around?  Thanks Siliviu for the input.  Right now, I am just using what I wrote originally, though Siliviu's option would still use the Mouse.Click's interal wait, and may be the way I have to go in the future as a workaround.

    -Micah

    Thursday, June 17, 2010 3:55 PM
  • It cannot click at the point specified because the element at that point is a IMG, not a Cell. The CodedUI Test playback algorithm will try to get the Cell into foreground, but it will never be able to in this scenario since the relative point in the Cell is always obscured by the IMG.
    Thursday, June 17, 2010 4:57 PM
  • Hi MrMicah,

     

    I am also facing this issue. If u got any method to overcome this issue please help me.......

    http://social.msdn.microsoft.com/Forums/en/vsautotest/thread/d192eedc-d5c7-419b-9a11-5e9467d97cdd

    Thankyou

     

     

    Tuesday, September 14, 2010 8:44 AM