使用新的Appium-java TouchActions的ClassCastException

use*_*016 8 appium

我在新的TouchActions课程中遇到错误.

  • JDK版本:1.8
  • 鸦片:1.7.2
  • appium.java-client.version:6.0.0-BETA2
  • selenium.java.version:3.8.1

 

TouchActions actions = new TouchActions(appiumDriver);
Run Code Online (Sandbox Code Playgroud)

运行时错误:

java.lang.ClassCastException:io.appium.java_client.ios.IOSDriver无法强制转换为org.openqa.selenium.interactions.HasTouchScreen

然而,旧的以下工作都很好:

TouchAction touchAction = new TouchAction(appiumDriver);
Run Code Online (Sandbox Code Playgroud)

小智 1

使用io.appium.java_client.TouchAction类。

步骤1

TouchAction action = new TouchAction(driver);
Run Code Online (Sandbox Code Playgroud)

driver是 的一个实例AppiumDriver

第2步

WebElement ele = driver.findElement(By.id("locator"));

action.tap(new TapOptions().withElement(new ElementOption().withElement(ele))).perform();
Run Code Online (Sandbox Code Playgroud)

使用新的实现,TouchAction您无法直接传递 webment。

使用的依赖项

<dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>7.0.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)