问题
I used the Actions to mouse hover in FF and chrome , it is working fine. But the same code is not working in safari. I am using mac OS and selenium webdriver and java.
I tried below code.
new Actions(driver).moveToElement(element).build().perform();
JS:
String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(mouseOverScript, element);
It is a show stopper issue. any help is appreciated.
回答1:
Performing mouse hovers requires using WebDriver's Advanced User Interactions API. In the Java language bindings, this is accomplished by the Actions
class. Unfortunately, at present, the SafariDriver
does not implement the Advanced User Interactions API, so you cannot accomplish this directly. Until it is implemented, you could probably simulate it using JavaScript to fire the events fired my a mouse hover.
来源:https://stackoverflow.com/questions/26655628/mouse-hover-is-not-working-in-safari-selenium-web-driver