我使用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();」); –