3

I work on a suite of automated tests that have been developed using WatiN and MBUnit. I've heard that it's possible to get WatiN to 'hover' over an element, but I can't seem to get it working using the methods I've used in the past. Is there another way to do this that I don't know about? I've tried using just FireEvent 'onmouseover', and using the FireEvent plus clicking on the link.

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

Any suggestions? Thanks in advance!

Jen Bandelin
  • 193
  • 2
  • 12

2 Answers2

0
    /// <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 both on IE 11 and FF.

rahoolm
  • 733
  • 2
  • 12
  • 22
0

Try using the MouseEnter method on the object you want to hover.

Here's an example:

hoverLink.MouseEnter();
Waylon Flinn
  • 19,969
  • 15
  • 70
  • 72