HtmlButton click does not work

Oct 31, 2012 at 5:22 PM

Hi! What a great library this is, makes coded UI tests actually usable...

One problem though, the Click extension method did not actually clicked my buttons (links worked ok).

When I changed the click coordinate from (1, 1) to (5, 5) and rebuilt the library everything worked much better.

Oct 31, 2012 at 7:09 PM

I ran into the same problem on numerous controls. This is who I corrected it with an extension of the UITestControl Object.

public static bool Click(this UITestControl control)
        {
            try
            {
                if (control.CheckControl())
                {
                    try
                    {
                        //Scroll to the Object if possible, other move on
                        control.EnsureClickable();
                    }
                    catch (Exception)
                    {
                        //HtmlCustoms objects will throw an exception with this call
                        //Silence this exception 
                    }
 
                    System.Drawing.Point clickPoint = new System.Drawing.Point();
                    clickPoint.X = control.BoundingRectangle.X + (control.BoundingRectangle.Width / 2);
                    clickPoint.Y = control.BoundingRectangle.Y + (control.BoundingRectangle.Height / 2);
 
                    Mouse.Move(clickPoint);
                    Mouse.Click();
                    return true;
                }
                else
                {
                    Logger.LogImage(control, control.Name + "_controlInError");
                    return false;
                }
            }
            catch (Exception e)
            {
                Logger.Log("Caught exception : " + e.Message);
                return false;
            }
        }