使用 Appium TouchActions 的 ClassCastException [英] ClassCastException on using Appium TouchActions

查看:23
本文介绍了使用 Appium TouchActions 的 ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Appium TouchActions 类执行点击操作,但会引发异常.请提供您的解决方案.

Im trying to perform tap action using Appium TouchActions class, but it throws exceptions. Please provide your solution.

import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.interactions.touch.TouchActions;
===========================================================
WebDriver driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities());
        Thread.sleep(5000);
        String title = driver.findElement(By.id("app_title")).getText();
        System.out.println("TITLE: " + title);
        WebElement ele = driver.findElement(By.id("bt1"));
        TouchActions touch = new TouchActions(driver);
        touch.singleTap(ele);
        touch.perform();

输出和异常:

Aug 02, 2018 6:51:11 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
TITLE: TestApp
java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen
at org.openqa.selenium.interactions.touch.TouchActions.<init>(TouchActions.java:38)
at scratchpad.MobileAutomation.main(MobileAutomation.java:23)

Process finished with exit code 0

使用的版本:硒-java:3.11.0java-client(io.appium): 5.0.4

如果您需要任何其他信息,请告诉我.还给我建议执行移动操作的最佳方式,如滑动(所有方向)、点击、双击、长按等.提前致谢.

Let me know, if you want any other information. Also give me suggestion best way to perform Mobile operation such as swipe(all direction), tap, double tap, long press, etc. Thanks in advance.

推荐答案

使用 Appium TouchAction 而不是 Selenium TouchActions.将以下代码放入测试类的父类中也很少:

Use Appium TouchAction instead of Selenium TouchActions. It is also handful to put the below code into parent of your test class:

import io.appium.java_client.TouchAction;

public AndroidDriver<MobileElement> driver = new TouchAction(driver);

public void tap(MobileElement element) {

  getTouchAction()
    .tap(
      new TapOptions().withElement(
        ElementOption.element(
          element)))
    .perform();
}

调用方法():

tap(myMobileElement);

这篇关于使用 Appium TouchActions 的 ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆