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