appium-android - 使用 TouchActions 在 android app + appium 中滚动
问题描述
我正在对我的 Android 应用程序进行自动化测试,并且需要滚动才能看到滚动所需的字段。我尝试从这里
使用以下代码:
TouchActions action = new TouchActions(driver);
action.scroll(element, 10, 100);
action.perform();
运行此代码后,它给了我这个错误:
java.lang.ClassCastException:
io.appium.java_client.android.AndroidDriver cannot be cast to
org.openqa.selenium.interactions.HasTouchScreen
好吧,我知道我已经通过了TouchActions
type的驱动程序AndroidDriver
。
我将如何解决这个问题?
解决方案
请使用 TouchAction 而不是 TouchAction s
TouchAction action = new TouchAction(androidDriver);
int height = androidDriver.manage().window().getSize().height;
int width = androidDriver.manage().window().getSize().width;
action.press(PointOption.point(width / 2, height / 2))
.moveTo(PointOption.point(width / 2, height * 3 / 4)).release().perform();
推荐阅读
- ios - 如果视图控制器在 UINavigationController 中,则 UICollectionViewLayout shouldInvalidateLayout(forBoundsChange:) 方法不会在设备旋转时调用
- graphql - Gatsby 组件中的多个查询
- git - 保存每次运行的 rmarkdown 文件以供记录
- html - 无法使用 fullcalendar 将日历的大小占据所有宽度
- html - HTML页面无法向下滚动并且内容隐藏在页脚后面
- python - 如何从创建日期 Django 开始正好 30 秒
- networking - nftables - 丢弃特定网桥上的 arp 流量
- java - 我可以使用方法名称来创建 Spring JPA 更新查询吗?
- python - 模块“keras.backend”没有属性“unique_object_name”
- kubernetes - 将 Prometheus 部署到不同的 Kubernetes 集群