1.按壓press
開始按壓一個元素或坐標點(x,y)。通過手指按壓手機屏幕的某個位置。
press(WebElement el, int x, int y)
比如TouchAction(driver).press(x=0,y=308).release().perform()
-
release() 結束的行動取消屏幕上的指針。釋放,相當於松手
-
Perform() 執行的操作發送到服務器的命令操作。
2.長按控件
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();
3.點擊控件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();
4.移動 moveto
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();
5.暫停 wait()
action.wait(1000); 單位為毫秒