Appium基础操作之九宫格滑动解锁

zh前的swipe API提供的操作可以实现单向滑动,如果想要实现类似于九宫格这种连续的滑动需求,该怎么做呢?

TouchAction包含一系列的操作,比如按压、长按、点击、移动、暂停等,可以由这些操作组成一组工作来完成实际的连续滑动需求。

在分析实际需求时,我们会发现有两种情况:

第一种 :整个解锁图案就是一个view,没有其他子元素,那么我们就只能采取坐标的形式

#首先得到对应 滑动解锁经过的坐标点
element=driver.find_element_by_id("com.xxzb.fenwoo:id/lpv_password")
#获取起始坐标-九宫格左上顶点
loc=element.location
#获取元素大小
size=element.size
#获取分割后的均值,即下面要用到的九宫格的步长
step=size["height"]/6
#得到九宫格绘制的起点坐标,这里例子为第一个坐标点
start_x=loc["x"]+step
start_y=loc["y"]+step
#滑动九宫格操作,从第一个点、一次滑动到第二个、第三个、第五个、第九个
ta=TouchAction(driver)
ta.press(x=start_x,y=start_y).wait(200).\
    move_to(x=start_x+step*2,y=start_y).wait(200).\
    move_to(x=satrt_x+step*4,y=start_y).wait(200).\
    move_to(x=start_x+step*2,y=start_y+step*2).wait(200).\
    move_to(x=start_x+step*4,y=start_y+step*4).wait(200).\
    release().wait(200).\
    perform()

 第二种情况是:九个点不是由一整个view构成,而是由分开的imageview的集合构成

#得到所有imageview的集合
images=driver.find_elements(By.xpath,"//android.widget.FrameLayout/android.widget.ImageView")
#滑动
ta=TouchAction(driver)
ta.press(images[0])wait(200).\
    move_to(images[1]).wait(200).\
    move_to(images[2]).wait(200).\
    move_to(images[4]).wait(200).\
    move_to(images[9]).wait(200).\
    release().wait(200).\
    perform()

  

猜你喜欢

转载自www.cnblogs.com/123blog/p/12622325.html
今日推荐