第一種懸停方法:spa
action.clickAndHold();// 鼠標懸停在當前位置,既點擊而且不釋放code
action.clickAndHold(onElement);// 鼠標懸停在 onElement 元素的位置seo
不過clickAndHold不能徹底模擬鼠標懸停,而是會致使二級菜單的閃現,須要用jsip
第二種懸停方法:get
public static void MouseHoverByJavaScript(WebElement targetElement,WebDriver driver)it
{io
String mouseHoverjs = "var evObj = document.createEvent('MouseEvents');" +class
"evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" +cli
"arguments[0].dispatchEvent(evObj);";方法
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(mouseHoverjs, targetElement);
}