使用Appium TouchActions的ClassCastException [英] ClassCastException on using Appium TouchActions
问题描述
我正在尝试使用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.0 java-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
代替硒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屋!