Selenium Actions 不适用于版本 3.141.59

Selenium Actions not working with version 3.141.59

主要问题是我们正在尝试更新 POM 以使用 Selenium 的 3.141.59 版。在我们的更新过程中,我们注意到 Actions 有几个错误。阅读文档后我们发现:

"import org.openqa.selenium.interactions.Actions;" has been deprecated and replaced with "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 的更改日志中找到这条注释:

Deprecated the original Actions API in favour of the W3C approach.

这里是一个简单的例子,如果它有帮助的话。

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

正如@Tyler 在对我有用的评论中所建议的那样:我能够这样做,我们发现它是 Appium 版本。如果您将 Selenium 更新到最新版本,您将需要我们正在使用的 Appium 7.0.0

将Appium版本也更新到7.0。