Question

There are some buttons and menus in the application I am testing that require actual clicks to send all the information through and FireEvent style clicking does not seem to cut it. Both TestPartner and QTP can use actual clicks. TestPartner does this always (slow) and QTP does this by changing the 'ReplayType' to 2 from 1.

Setting.WebPackage("ReplayType") = 2

So my question is. Is there anyway to get real clicks in WatiN or Selenium? I have not been able to find that option.

Thank You, Josh

Was it helpful?

Solution

Selenium 2 can fire real clicks instead of trying to synthesize the clicks and keystrokes like Selenium 1 does. It does a lot of interaction with the OS to do these things natively which over comes a lot of the Selenium 1 issues like is it firing a click or mouseup or mousedown?

Selenium 2 is in its 2nd alpha phase and is quite stable at the moment. You can get Selenium 2.0a2 from http://code.google.com/p/selenium/downloads/list.

I have been working on the .NET bindings and am really happy with the way they are going.

OTHER TIPS

When ReplayType is set to device (2), QTP actually moves the mouse and performs a click (you can see the mouse cursor move). I'm not very familiar with Selenium but from what I know replay is done in pure JavaScript therefore it can fire DOM events (as QTP does in event ReplayMode) but it can't simulate a real click the way QTP does.

With WatiN, it is possible to get to the "native" interface of elements in IE windows. Using that you can get the screen coordinates of any element.

using mshtml; //Add a reference to Microsoft.mshtml that comes with WatiN.
using WatiN.Core.Native.InternetExplorer;

public static System.Drawing.Point GetScreenPoint(IEElement element)
{
    IHTMLElement nativeElement = element.AsHtmlElement;
    IHTMLElement2 offsetElement = (IHTMLElement2)nativeElement;
    IHTMLRect clientRect = offsetElement.getBoundingClientRect();
    IHTMLDocument2 doc = (IHTMLDocument2)nativeElement.document;
    IHTMLWindow3 window = (IHTMLWindow3)doc.parentWindow;

    int windowLeft = window.screenLeft;
    int windowTop = window.screenTop;
    int elementLeft = clientRect.left;
    int elementTop = clientRect.top;
    int width = nativeElement.offsetWidth;
    int height = nativeElement.offsetHeight;

    int clickX = windowLeft + elementLeft + (width / 2);
    int clickY = windowTop + elementTop + (height / 2);

    return new System.Drawing.Point(clickX, clickY);
}

To use it:

Button myButton = browser.Button(Find.ById("myButton"));
System.Drawing.Point clickPoint = GetScreenPoint((IEElement)myButton.NativeElement);
MyClick(clickPoint);

Obviously the element has to be visible. I don't know how to check for that offhand, but I think you can change the scrollTop and scrollLeft attributes of the body to scroll around.

You'll also need a method to actually do the click, but there's probably an answer for that already on stackoverflow.

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