我试图使用Appium TouchActions类执行tap操作,但它抛出了异常。请提供您的解决方案。
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.110java客户端(io.apium(:5.0.4
如果你想了解其他信息,请告诉我。也给我建议最好的方式来执行移动操作,如滑动(所有方向(,点击,双击,长按等。提前谢谢。
使用AppiumTouchAction
而不是SeleniumTouchActions
。将以下代码放入测试类的父级也是很难的:
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);
您可以使用TouchAction存在一些问题这是一个的例子
TouchAction t = new TouchAction(driver);
t.tap(TapOptions.tapOptions().withElement(ElementOption.element(webElementForExpandibleList))).perform();