实现思路:
为了适应不同屏幕的滑动解锁,实现思路:
1.获取九宫格patterview的起始坐标x、y
2.获取九宫格patterview的宽度(width)、高度(height)
3.九宫格的九个格子大约平均把patterview的长、宽平均分成了4个等分,宽度间隔为width/4、高度间隔为height/4
4.第一个格子的坐标为(x+width/4, y+height/4)
5.每次滑动的时候,就相当于横坐标(纵坐标)的变化量△x为width/4(△y为height/4)
6.使用TouchAction、moveTo方法实现滑动即可
实现代码:
@Test /*** * 卡包滑动解锁 * resourceId---cn.xxxx.xxxx.android:id/xxxx_card_pw_patterview * @throws Exception */ public void c_slideUnlock() throws Exception{ driver.findElementById("cn.xxxx.xxxx.android:id/xxxx_tv_card_package").click(); Thread.sleep(1000); WebElement patterview = driver.findElementById("cn.xxxx.xxxx.android:id/xxxx_card_pw_patterview"); //获取控件起始坐标的x、y int xStartPoint = patterview.getLocation().getX(); int yStartPoint = patterview.getLocation().getY(); //获取控件的高度、宽度 int width = patterview.getSize().getWidth(); int height = patterview.getSize().getHeight(); //宽度、高度之间的间隔 int xStep = width/4; int yStep = height/4; //patterview起始坐标的x、y;第一个格子与控件起始坐标相差一个间隔 int x = xStartPoint + xStep; int y = yStartPoint + yStep; TouchAction slide = new TouchAction(driver).press(x, y).waitAction(500).moveTo(0, yStep).waitAction(500).moveTo(0, yStep).waitAction(500) .moveTo(xStep, 0).release(); slide.perform(); WebDriverWait wait = new WebDriverWait(driver, 20); WebElement e = wait.until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver d) { return d.findElement(By.name("绑定卡")); } }); driver.findElementById("cn.xxxx.xxxx.android:id/xxxx_base_iv_back").click(); }