注入 JavaScript 片段以触发“mouseover”和“mouseout”事件。适用于 Chrome、Firefox 和 Safari(本地和远程)。
对于 IE11,我可以验证它是否可以在控制台中运行。但是当试图自动化它时,会抛出错误:
JavaScript error (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 64 milliseconds Build info: version: '2.53.0', revision: '35ae25b',
time: '2016-03-15 17:00:58' System info: host: '185-129-68-90', ip: '185.129.68.90', os.name: 'windows',
os.arch: 'x86', os.version: '10.0',
java.version: '1.8.0_121' Driver info: org.openqa.selenium.ie.InternetExplorerDriver Capabilities
[{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal,
ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS,
nativeEvents=true, ie.ensureCleanSession=true, elementScrollBehavior=0, ie.browserCommandLineSwitches=,
requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=about:blank, takesScreenshot=true,
javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true,
unexpectedAlertBehaviour=dismiss}]
使用: WebdriverIO - 版本 4.6.2
代码片段:
hoverOnChart: function(chartID, index) {
browser.execute((chartID, index) => {
$(`${chartID} g.amcharts-graph-column:nth-child(${index})`).trigger("mouseover");
}, chartID, index);
}
注意:在上述场景中,我试图将鼠标悬停在使用amcharts
JavaScript 库创建的图表上。