前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >appium实现向上滑动,向下滑动,向左滑动,向右滑动

appium实现向上滑动,向下滑动,向左滑动,向右滑动

作者头像
小小咸鱼YwY
发布2020-06-19 15:02:26
5.7K0
发布2020-06-19 15:02:26
举报
文章被收录于专栏:python-爬虫python-爬虫

一.配置连接

代码语言:javascript
复制
from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'  # 系统名
desired_caps['platformVersion'] = '5.1.1' # adb版本 
desired_caps['deviceName'] = 'emulator-5554' # adb的名字 cmd输入adb devices可以查到

#导出模拟器中的apk,然后使用Android Kille将APK包进行反编译
desired_caps['appPackage'] = 'com.liulianp.android' # app的包名 
desired_caps['appActivity'] = 'com.liulianp.android.module.welcome.SplashActivity' # app的主入口名
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True


#启动appium-desktop服务器,服务器IP根据实际填写
ip = 'appnium的IP'
prot = 'appnium的prot'
driver = webdriver.Remote(f'http://{id}:{prot}/wd/hub', desired_caps)

二.向各个方向滑动

代码语言:javascript
复制
#原理使用driver.swipe方法()  swipe(self, start_x, start_y, end_x, end_y, duration=None)
start_x:起始横坐标
start_y:起始纵坐标
end_x:结束横坐标
end_y:结束纵坐标
duration:起始位置到结束位置用时间单位ms
#你可以把它想象成手指在app界面的一开始按着的位置到结束的位置
代码语言:javascript
复制
def get_size(driver):
    '''获取长宽'''
    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']
	return x,y

def swipeUp(driver, t=500, n=1):
    '''向上滑动屏幕'''
    x,y=get_size(driver)
    x1 = x * 0.5
    y1 = y * 0.2
    y2 = y * 0.8 
    for i in range(n):
        driver.swipe(x1, y1, x1, y2, t)

def swipeDown(driver, t=500, n=1):
    '''向下滑动屏幕'''
    x,y=get_size(driver)
    x1 = x * 0.5        
    y1 = y * 0.2       
    y2 = y * 0.8       
    for i in range(n):
        driver.swipe(x1, y1, x1, y2,t)

def swipLeft(driver, t=500, n=1):
    '''向左滑动屏幕'''
    x,y=get_size(driver)
    x1 = x * 0.8
    y1 = y * 0.5
    x2 = x * 0.2
    for i in range(n):
        driver.swipe(x1, y1, x2, y1, t)

def swipRight(driver, t=500, n=1):
    '''向右滑动屏幕'''
    x,y=get_size(driver)
    x1 = x * 0.2
    y1 = y * 0.5
    x2 = x * 0.8
    for i in range(n):
        driver.swipe(x1, y1, x2, y1, t)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-04-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一.配置连接
  • 二.向各个方向滑动
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档