Appium-滑动操作

appium 提供给了 driver.swipe()方法进行页面滑动操作

 1     def swipe(self: T, start_x: int, start_y: int, end_x: int, end_y: int, duration: int = 0) -> T:
 2         """Swipe from one point to another point, for an optional duration.
 3 
 4         Args:
 5             start_x: x-coordinate at which to start
 6             start_y: y-coordinate at which to start
 7             end_x: x-coordinate at which to stop
 8             end_y: y-coordinate at which to stop
 9             duration: time to take the swipe, in ms.
10 
11         Usage:
12             driver.swipe(100, 100, 100, 400)
13 
14         Returns:
15             Union['WebDriver', 'ActionHelpers']: Self instance坐标

 

坐标:X轴是从左到右的,Y轴是上从上到下的

  通过driver.get_windows_size 获取屏幕分辨率字典

  下滑操作:即从Y * 0.2的位置滑动到Y *0.8的位置,即 start_y = driver.get_windows.size().get('height') * 0.2     end_y = driver.get_windows.size().get('height') * 0.8 

  其他滑动操作类似,记得坐标即可

 

 1 from appium import webdriver
 2 
 3 desired_capabilities = {
 4     "deviceName":"192.168.221.102:5555",  #手机唯一ID
 5     "platformVersion":"5.0", #手机版本
 6     "platformName":"Android", # 设备类型
 7     "appPackage":"com.android.settings", #包名 'com.tencent.mobileqq'
 8     "appActivity":".Settings", #入口 tv.danmaku.bili.ui.splash.SplashActivity
 9     "noReset": True
10 }
11 
12 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_capabilities)
13 
14 size = driver.get_window_size()
15 width = size.get('width')
16 height = size.get('height')
17 print(size)
18 
19 #居中上滑
20 start_x_end = width * 0.5
21 start_y = height * 0.8
22 end_y = height * 0.2
23 
24 driver.swipe(start_x_end,start_y,start_x_end,end_y)

 

posted @ 2020-08-07 11:46  布谷鸟的春天  阅读(611)  评论(0编辑  收藏  举报