Powered By Blogger

Search Here!

Friday, August 9, 2013

Mouse Hover Event in WebDriver !

This is widely known issue among web driver community, how to perform mouse hover.  I have many scenarios in my test where I needed to perform mouse hover to see calendar, email schedule etc. After many attempts, I found solution which is actually working very well for me but I am not sure if it’s going to work with your application of not.  

protected void PerformMouseHoverByJavaScriptExecutor(IWebElement webElement)
        {
            const String javaScript = "var evObj = document.createEvent('MouseEvents');" +
                                      "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" + "arguments[0].dispatchEvent(evObj);";
            IJavaScriptExecutor javaScriptExecutor = WebDriver as IJavaScriptExecutor;
            javaScriptExecutor.ExecuteScript(javaScript, webElement);

        }

2 comments: