Selenium Actions 不适用于版本 3.141.59
·
问题:Selenium Actions 不适用于版本 3.141.59
主要问题是我们正在尝试更新我们的POM以使用Selenium的 3.141.59 版本。在更新过程中,我们注意到Actions有几个错误。在阅读文档后,我们发现:
“导入 org.openqa.selenium.interactions.Actions;”已被弃用并替换为“import org.openqa.selenium.interactions.Action”。
我们希望保持相同的行为并更新我们的代码以使用新的导入。我们还没有看到任何关于如何实际使用它的新文档。下面是我们如何使用旧动作的示例。
try {
Actions actions = new Actions(driver);
actions.moveToElement(searchDocument);
actions.sendKeys(PDF);
Thread.sleep(1000);
actions.build().perform();
} catch(Exception e) {
}
我能够在 Selenium 的更改日志中找到此注释:
弃用了原始的 Actions API 以支持 W3C 方法。
解答
这是一个简单的例子,如果它有帮助的话。
Actions actions = new Actions(driver);
// create the mouserover action
Action mouseOverOnElement = actions.moveToElement(linkMenu).build();
// get the back ground color before mouse over
String bgColor = linkMenu.getCssValue("background-color");
System.out.println("Before hover: " + bgColor);
// perform the mouseover operation
mouseOverOnElement.perform();
// get the back ground color after mouse over
bgColor = linkMenu.getCssValue("background-color");
System.out.println("After hover: " + bgColor);
硒文档:https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/Action.html
更多推荐

所有评论(0)