首页 技术 正文
技术 2022年11月12日
0 收藏 637 点赞 3,617 浏览 2009 个字

appium滑动操作(向上滑动、向下滑动、向左滑动、向右滑动)

测试app:今日头条apk

测试设备:夜游神模拟器

代码如下:

先用x、y获取当前的width和height

def getSize():                               #获取当前的width和height的x、y的值
x = driver.get_window_size()['width'] #width为x坐标
y = driver.get_window_size()['height'] #height为y坐标
return (x, y)

屏幕向上滑动

def swipeUp(t):  #当前向上滑动swipeup
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.75)
y2 = int(l[1] * 0.25)
driver.swipe(x1, y1, x1, y2,500) #设置时间为500
swipeUp(9000) #向上滑动9000

屏幕向左滑动

def swipLeft(t):      #当前向左进行滑动swipleft
l=getSize()
x1=int(l[0]*0.75)
y1=int(l[1]*0.5)
x2=int(l[0]*0.05)
driver.swipe(x1,y1,x2,y1,500)
swipLeft(3000) #向左滑行3000

屏幕向右滑动

def swipRight(t): #向右滑行swipright
l=getSize()
x1=int(l[0]*0.05)
y1=int(l[1]*0.5)
x2=int(l[0]*0.75)
driver.swipe(x1,y1,x2,y1,500)
swipRight(3000) #向右滑行3000,回到初始位置

屏幕向下滑动

def swipeDown(t):    #向下滑动swipedown
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.25)
y2 = int(l[1] * 0.75)
driver.swipe(x1, y1, x1, y2,500)
swipeDown(10000) #向下滑动10000

测试今日头条向上、向下、向左、向右滑动操作完整代码

#coding=utf-8
from appium import webdriver
import time
desired_caps={
'platformName':'Android',
'deviceName':'127.0.0.1:62001', #模拟器名称
'platformVersion':'4.4.2', #安卓版本
'appPackage':'com.ss.android.article.news', #当前apk的包名
'appActivity':'com.ss.android.article.news.activity.SplashBadgeActivity' #当前apk的appActivity
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(10)def getSize(): #获取当前的width和height的x、y的值
x = driver.get_window_size()['width'] #width为x坐标
y = driver.get_window_size()['height'] #height为y坐标
return (x, y)def swipeUp(t): #当前向上滑动swipeup
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.75)
y2 = int(l[1] * 0.25)
driver.swipe(x1, y1, x1, y2,500) #设置时间为500
swipeUp(9000) #向上滑动9000def swipLeft(t): #当前向左进行滑动swipleft
l=getSize()
x1=int(l[0]*0.75)
y1=int(l[1]*0.5)
x2=int(l[0]*0.05)
driver.swipe(x1,y1,x2,y1,500)
swipLeft(3000) #向左滑行3000def swipeDown(t): #向下滑动swipedown
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.25)
y2 = int(l[1] * 0.75)
driver.swipe(x1, y1, x1, y2,500)
swipeDown(10000) #向下滑动10000def swipRight(t): #向右滑行swipright
l=getSize()
x1=int(l[0]*0.05)
y1=int(l[1]*0.5)
x2=int(l[0]*0.75)
driver.swipe(x1,y1,x2,y1,500)
swipRight(3000) #向右滑行3000,回到初始位置
time.sleep(20)
driver.quit() #退出当前的app
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289