繁体   English   中英

如何在Selenium 2中使用JavaScript执行器将鼠标悬停?

[英]How to mouse hover using javascript executor in selenium 2?

目前在Selenium WebDriver中使用Java 我想在鼠标悬停到选项卡上时执行操作,它需要单击选项卡。 在此代码中,我可以识别该元素,并且它正在打开选项卡。 但是问题在于它不是鼠标悬停和没有点击,而是直接打开页面。

 JavascriptExecutor executor = (JavascriptExecutor)driver;
         executor.executeScript("arguments[0].click();",                                                     
driver.findElement(By.id("ext-pr-backlog-evolution") ));

如果我使用

WebElement menuHoverLink = driver.findElement(By.id("ext-pr-backlog-evolution"));
actions.moveToElement(menuHoverLink).click().perform();

它不能完全找到元素,而是单击其他标签。 所以我想将鼠标悬停在javascript执行器中。

您可以创建一个鼠标事件

document.createEvent('MouseEvents');

然后将鼠标悬停给它

mouseEventObj.initEvent( 'mouseover', true, true );

然后分派

element.dispatchEvent(mouseEventObj);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM