Hover over an item with WatiN

I am working on a suite of automated tests that have been developed using WatiN and MBUnit. I heard that you can make WatiN hang over an element, but I cannot get it to work using methods that I used in the past. Is there any other way to do this that I don't know about? I tried to use FireEvent "onmouseover" and use FireEvent plus click on the link.

myDiv.HoverLink.FireEvent("onmouseover");
myDiv.HoverLink.Click();

Any suggestions? Thanks in advance!

+3
source share
2 answers

Try using the method MouseEnterfor the object you want to hover.

Here is an example:

hoverLink.MouseEnter();
0
source
    /// <summary>
    /// Mouse Over on given <see cref="Element"/>
    /// </summary>
    /// <param name="element">element</param>
    /// <returns>Nothing</returns>
    public static void MouseOver(this Element element)
    {
        var jref = element.GetJavascriptElementReference();
        var dom = element.DomContainer;

        var evt = new JSEventCreator(jref, null);
        var evtProp = new NameValueCollection();
        evtProp.Add("windowObject", "window");

        var scriptCode = evt.CreateMouseEventCommand("mouseover", evtProp);
        Logger.LogDebug(scriptCode);
        scriptCode = scriptCode.ToString() + jref + ".dispatchEvent(event);";

        string result = dom.Eval(scriptCode);
        Logger.LogAction(result);
        dom.WaitForComplete();
        Thread.Sleep(TimeSpan.FromSeconds(2));
    }

This is what I did, and it works on both IE 11 and FF.

0
source

All Articles