【问题标题】:ClassCastException on using Appium TouchActions使用 Appium TouchActions 时出现 ClassCastException
【发布时间】:2019-01-10 07:41:21
【问题描述】:

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

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.0 java-client(io.appium): 5.0.4

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

【问题讨论】:

  • 考虑使用 MobileElement 或 AndroidElement 而不是 WebElement
  • touch.singleTap(ele);只接受 WebElement,而不接受 MobileElement 或 AndroidElement。先生,您要说什么?

标签: selenium-webdriver mobile appium ui-automation java-client


【解决方案1】:

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

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);

【讨论】:

    【解决方案2】:

    您可以使用 TouchAction 存在一些问题 这是一个例子

    TouchAction t = new TouchAction(driver);
            t.tap(TapOptions.tapOptions().withElement(ElementOption.element(webElementForExpandibleList))).perform();
    

    【讨论】:

      猜你喜欢
      • 2018-07-05
      • 1970-01-01
      • 2017-09-15
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      相关资源
      最近更新 更多