android - 如何进行水平滑动直到在 webdriverio 中找到用于移动自动化的所需元素?
问题描述
我想做水平滑动有没有什么方法可以使用appium webdriverio为Android手机完成。
解决方案
您可以使用io.appium.java_client.TouchAction创建自定义滑动方法
public void horizontalSwipeByPercentage(double startPercentage, double endPercentage,
double anchorPercentage, AppiumDriver<MobileElement> driver) {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * endPercentage);
new TouchAction(driver)
.press(PointOption.point(startPoint, anchor))
.waitAction(WaitOptions.waitOptions(ofSeconds(1)))
.moveTo(PointOption.point(endPoint, anchor))
.release().perform();
}
对于水平滑动,anchor 是固定的 y 坐标位置
推荐阅读
- c++ - 如何对g ++设置执行时间限制?
- symfony - 如何按名称对 Doctrine 对象进行排序?
- c - 如何离开(中断)waitpid()函数?
- odoo - create() 正好接受 2 个参数(1 个给定)
- bash - 如何根据 .MTS 视频文件的创建日期和修改日期将数组拆分为多个
- git - 从之前分叉的存储库创建新分支
- css - 带有 flex-wrap 的 Flex div 不换行
- python - 如何收集生成器和判别器的可训练变量?(张量流)
- java - 为什么 java.util.Properties 扩展 Hashtable
- javascript - 装饰器、Webpack 和 ProvidePlugin