Appium自动化测试(12)—— Appium API 之 TouchAction 操作

Appium的辅助类,主要针对手势操作,比如滑动、长按、拖动等。

按压控件

方法:

  • press()

开始按压一个元素或坐标点(x,y)。通过手指按压手机屏幕的某个位置。

press(WebElement el, int x, int y)

press也可以接收屏幕的坐标(x,y)

例:

TouchAction(driver).press(x=0, y=308).release().perform()

除了press()方法之外,本例中还用到了别外两个新方法:

  • release() 结束的行动取消屏幕上的指针
  • perform() 执行的操作发送到服务器的命令操作

长按控件

方法:

  • longPress()

开始按压一个元素或坐标点(x,y)。 相比press()方法,longPress()多了一个入参,既然长按,得有按的时间吧。duration以毫秒为单位。1000表示按一秒钟。其用法与press()方法相同。

longPress(WebElement el, int x, int y, Duration duration)

例:

TouchAction action = new TouchAction(driver);
action.longPress(names.get(1), 1000).perform().release();
action.longPress(1, 302, 1000).perform().release();

点击控件

方法:

  • tap()

对一个元素或控件执行点击操作。用法参考press()。

tap(WebElement el, int x, int y)

例:

TouchAction action = new TouchAction(driver);
action.tap(names.get(1)).perform().release();
action.tap(1, 302).perform().release();

移动

方法:

  • moveTo()

将指针(光标)从过去指向指定的元素或点。

movTo(WebElement el, int x, int y)

其用法参考press()方法。

例:

TouchAction action = new TouchAction(driver);
action.moveTo(names.get(1)).perform().release();
action.moveTo(1, 302).perform().release();

暂停

方法:

  • wait()

暂停脚本的执行,单位为毫秒。

action.wait(1000);
上一篇 Appium自动化测试(11)—— Appium API 之键盘操作
下一篇 Appium自动化测试(13)—— Appium API 之其他操作
目录
文章列表
1 SpringBoot-Google二步验证
SpringBoot-Google二步验证
2
Spring Cloud获取本地服务实例方法getLocalServiceInstance()过时
Spring Cloud获取本地服务实例方法getLocalServiceInstance()过时
3
React Native学习之ProgressBar组件
React Native学习之ProgressBar组件
4
CentOS 7搭建Nexus Maven私服
CentOS 7搭建Nexus Maven私服
5
Android设置ImageView图片灰度
Android设置ImageView图片灰度
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。