Appium swipe之螢幕上 下 左 右滑動

2022-08-25 13:33:25 字數 1833 閱讀 5864

這個方法用起來到也比較簡單,首先獲取螢幕的寬度、高度,然後計算出滑動的開始位置到結束位置的距離,

再把引數傳遞給swipe()呼叫即可:

不過要先弄清楚手機螢幕的起始座標位置,要不然,滑動時就打不到效果了。

手機螢幕的起始座標都是在左上角,也就是說左上角開始位置x軸、y軸都是0。弄清楚這一點,接一下來就好做了。

如下圖

具體實現**如下:

#-*-encoding:utf-8-*-

from time import sleep

desired_caps =

# pjqdu16715003110

}driver = webdriver.remote("",desired_caps)

sleep(5)

#獲取手機螢幕寬、高

x = driver.get_window_size()["width"]

y = driver.get_window_size()["height"]

# print x,y

def swipe_down(driver,start_y=0.25,stop_y=0.75,duration=3000):

#按下手機螢幕,向下滑動

#注意,向下滑時,x軸不變,要不然就變成了斜向下滑動了

#@duration:持續時間

x1 = int(x*0.5)

y1 = int(y*start_y)

x2 = int(x*0.5)

y2 = int(y*stop_y)

# print x1,y1,x2,y2

driver.swipe(x1,y1,x2,y2,duration)

def swipe_up(driver,start_y=0.75,stop_y=0.25,duration=3000):

#按下手機螢幕,向上滑動

#注意,向上滑時,x軸不變,要不然就變成了斜向下滑動了

#@duration:持續時間

x1 = int(x*0.5)

y1 = int(y*start_y)

x2 = int(x*0.5)

y2 = int(y*stop_y)

# print x1,y1,x2,y2

driver.swipe(x1,y1,x2,y2,duration)

def swipe_left(driver,star_x=0.75,stop_x=0.25,duration=3000):

#按下手機螢幕,向左邊滑動

#注意,向左邊滑時,y軸不變

#@duration:持續時間

x1 = int(x*star_x)

y1 = int(y*0.5)

x2 = int(x*stop_x)

y2 = int(y*0.5)

# print x1,y1,x2,y2

driver.swipe(x1,y1,x2,y2,duration)

def swipe_right(driver,star_x=0.25,stop_x=0.75,duration=3000):

#按下手機螢幕,向右邊滑動

#注意,向左邊滑時,y軸不變

#@duration:持續時間

x1 = int(x*star_x)

y1 = int(y*0.5)

x2 = int(x*stop_x)

y2 = int(y*0.5)

# print x1,y1,x2,y2

driver.swipe(x1,y1,x2,y2,duration)

選擇螢幕上做按鈕

report demo screen button.tables sscrfields.selection screen begin of block scr1 with frame title text 001.parameters p path type rlgrap filename defa...

操作螢幕上的視窗

未整理 tcsstr 字串1在字串2中首次出現的位置,未出現返回null值 tcsrchr 字元1 在字串2中首次出現的位置,未出現返回null值char szfilepath max path getmodulefilename null,szfilepath,max path tcsrchr s...

選擇螢幕上做按鈕

report mysap fi04 tables sscrfields selection screen begin of block scr1 with frame title text 001 parameters p path type rlgrap filename default c up...