appium元素定位和手势练习

Appium常用元素定位方式

可以通过id定位元素

el1 = driver.find_element_by_id("com.android.settings:id/title")

 可以通过xpath定位

el1=driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.view.View/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.TextView")

可以通过class

appium元素事件操作API

swipe滑动事件

swipe(start_x,start_y,end_x,end_y,duration=None)

driver.swipe(96,720,96,166,1000)

scroll滑动事件

el2 = driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")

el3 = driver.find_element_by_xpath("//*[contains(@text,'应用')]")

driver.scroll(el3,el2)

drag拖拽事件

el2 = driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")

el3 = driver.find_element_by_xpath("//*[contains(@text,'应用')]") driver.drag_and_drop(el3,el2)

手指轻敲操作

el2 = driver.find_element_by_xpath("//[contains(@text,'应用')]")

TouchAction(driver).tap(el2).perform()

按压press

每一个press之后都要一个releasw()和Perform

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

press(WebElement el, int x, int y)
比如TouchAction(driver).press(x=0,y=308).release().perform()

release() 结束的行动取消屏幕上的指针。释放,相当于松手

Perform() 执行的操作发送到服务器的命令操作。

长按控件

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

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

TouchAction action = new TouchAction(driver);

action.longPress(names.get( 200),1000).perform().release();

action.longPress( 200 ,200,1000).perform().release();

点击控件tap

tap(WebElement el, int x, int y)

TouchAction action = new TouchAction(driver);

action.tap(names.get(200)).perform().release();

action.tap( 200,200).perform().release();

移动 move_to

moveTo(WebElement el, int x, int y) TouchAction action = new
TouchAction(driver);

action.moveTo(names.get(200)).perform().release();

action.moveTo( 200,200).perform().release();

等待wait()

action.wait(1000); 单位为毫秒

练习

设置安全的屏幕锁定图案

 从WLAN滑动到应用

el2 = driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")

el3 = driver.find_element_by_xpath("//*[contains(@text,'应用')]")

driver.scroll(el3,el2)

点击安全

el4 = driver.find_element_by_xpath("//*[contains(@text,'安全')]")

el4.click()

点击屏幕锁定方式

el5 = driver.find_element_by_xpath("//*[contains(@text,'屏幕锁定方式')]")

el5.click()

设置图案

TouchAction(driver).press(x=88,y=366).wait(100).move_to(x=265,y=366).wait(100).move_to(x=450,y=520).wait(100).move_to(x=450,y=700).release().perform()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值