如何在Firefox 19中使用Selenium WebDriver进行鼠标悬停?

如何在Firefox 19中使用Selenium WebDriver进行鼠标悬停?

问题描述:

我用过硒2.31。

我使用了动作类进行鼠标移动。使用这个我将鼠标移动到一个菜单上,它的子菜单只出现了一小段时间,与旧版本的firefox不同。

I have used Actions class for mouse movement. Using this I moved the mouse over a menu and its submenu appeared only for a fraction of second unlike with older version of firefox .

由于此问题,我无法使用 driver.findElement 选择子菜单,因为它会抛出异常元素不能滚动到视图。

Beacuse of this issue I cannot select the sub menu using driver.findElement as it throws an exception "element cannot be scrolled into view".

这有什么解决方案吗?

使用actions对象,您应首先移动菜单标题,然后移动到弹出菜单项并单击它。不要忘记最后调用 actions.perform()。以下是一些示例Java代码:

With the actions object you should first move the menu title, and then move to the popup menu item and click it. Don't forget to call actions.perform() at the end. Here's some sample Java code:

Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.linkText("Menu heading"));
actions.moveToElement(menuHoverLink);

WebElement subLink = driver.findElement(By.cssSelector("#headerMenu .subLink"));
actions.moveToElement(subLink);
actions.click();
actions.perform();