我使用Selenium 3.0.1运行使用TestNG的自动化测试。 在一次测试中我试图悬停动作菜单,然后单击该菜单中的选项:moveToElement鼠标悬停功能在Selenium WebDriver中使用Java不稳定
Actions builder = new Actions(getWebDriver());
builder.moveToElement(actionButton).build().perform();
但测试并不稳定。我可以看到菜单打开但立即关闭,所以测试失败,因为它没有找到选项。 我收到此错误:
java.lang.IllegalArgumentException: Must provide a location for a move action.
at org.openqa.selenium.interactions.MoveMouseAction.<init>(MoveMouseAction.java:30)
at org.openqa.selenium.interactions.Actions.moveToElement(Actions.java:251)
我如何检查菜单打开? perform()方法返回void。 我注意到如果我把moveToElement调用两次,比测试更稳定。有没有这样做的优雅选择?
Actions builder = new Actions(getWebDriver());
builder.moveToElement(actionButton).build().perform();
builder.moveToElement(actionButton).build().perform();
我发现这个问题: https://sqa.stackexchange.com/questions/3467/issue-with-losing-focus-of-hover-command-when-the-mouse-is-outside-of-the-acti 这也解释了最好的我的问题。不幸的是,仍然没有解决方案。
这里的问题是,菜单不打开,但关闭之前硒能找到的子菜单按钮。我觉得FluentWait在这里不会有帮助,因为菜单已经关闭了,所以它只会等待一切。如果我错了,请纠正我。 我正在寻找的是一种在打开后冻结下拉菜单但不点击它的方法。 – sami610
很难说如果你的错误没有看到洞情节和网站本身......所以我会鼓励你先尝试等待。 – Moshisho
它是否也与JavaScriptExecutor一起使用? ((JavascriptExecutor)driver).executeScript(“$('element_selector')。hover();”); –