Selenium WebDriver鼠标操作moveToElement不会在Firefox Linux上引发mouseout事件

我一直在尝试使用Selenium WebDriver和Firefox 19在我的网页上测试工具提示。
我基本上试图使用鼠标操作将鼠标hover在附加了工具提示的元素上,以测试工具提示是否显示,并将鼠标hover在另一个元素上以测试工具提示是否隐藏。 第一个操作正常,但当hover在另一个元素上时,工具提示仍然可见。 手动测试网页时不会发生此问题。
有没有其他人遇到过这个问题? 我正在使用Ubuntu 12.04。

似乎Advanced Actions API依赖于本机事件,默认情况下在Linux版本的Firefox中禁用。 因此,必须在WebDriver实例中明确启用它们。

FirefoxProfile profile = new FirefoxProfile(); //explicitly enable native events(this is mandatory on Linux system, since they //are not enabled by default profile.setEnableNativeEvents(true); WebDriver driver = new FirefoxDriver(profile); 

此外,在我的情况下,我需要将WebDriver升级到版本2.31,因为hover( moveToElement )操作在2.30上无法正常工作,即使显式启用了本机事件也是如此。 使用WebDriver的2.31版和Linux上的Firefox版本17和19进行了测试。 有关更多信息,请查看此链接:
http://code.google.com/p/selenium/wiki/AdvancedUserInteractions#Native_events_versus_synthetic_events

我也在Firefox 19上遇到了Selenium 2.30这个问题。它在FF 18.2上工作正常。

这是一个简单但方便的方法,使用javascript调用将mouseout()事件发送到您指定的任何元素(我更喜欢使用By传递它们,但您可以将其更改为您喜欢的任何内容。

我在使用Chrome时出现问题,其中工具提示在点击后拒绝关闭,并遮挡了其他附近的点击事件,导致其失败。 在这种情况下,这种方法节省了一天。 希望它可以帮助别人!

  /** * We need this to close help text after selenium clicks * (otherwise they hang around and block other events) * * @param by * @throws Exception */ public void javascript_mouseout(By by) throws Exception { for (int i=0; i<10; i++) { try { JavascriptExecutor js = (JavascriptExecutor)driver; WebElement element = driver.findElement(by); js.executeScript("$(arguments[0]).mouseout();", element); return; } catch (StaleElementReferenceException e) { // just catch and continue } catch (NoSuchElementException e1) { // just catch and continue } } } 

您可以在任何类型的click()事件后调用它,如下所示:

 By by_analysesButton = By.cssSelector("[data-section='Analyses']"); javascript_mouseout(by_analysesButton); 

Fyi,我的尝试/捕获通过for循环尝试10倍,因为我们的应用程序倾向于Chrome过时的元素exception,所以如果你没有这个问题,这个方法可以大大减少。

我有同样的问题。 起初我使用了moveToElement()方法而没有perform() 。 然后我用setEnableNativeEvents添加了Firefox Profile ,但它仍然不适用于我。 最后我以这种方式解决了这个问题(只需添加perform()

  WebElement username = driver.findElement(By.id(“username”));
动作动作=新动作(驱动程序);
 actions.moveToElement(用户名).perform();
 WebElement tooltip = driver.findElement(By.id(“tooltip”));
 tooltip.isDisplayed(); 

它工作正常。