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' o开发者_运维技巧ver 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!
Try using the MouseEnter
method on the object you want to hover.
Here's an example:
hoverLink.MouseEnter();
/// <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.
精彩评论