在 Appium 中提供 swipe() 方法来模拟用户滑动屏幕。

swipe() 实现过程 是先通过在屏幕上标记两个坐标,然后再从开始坐标移动到结束坐标。

先看下 swipe 方法定义:

    def swipe(self, start_x, start_y, end_x, end_y, duration=None):
"""Swipe from one point to another point, for an optional duration. Args:
start_x (int): x-coordinate at which to start
start_y (int): y-coordinate at which to start
end_x (int): x-coordinate at which to stop
end_y (int): y-coordinate at which to stop
duration (:obj:`int`, optional): time to take the swipe, in ms. Usage:
driver.swipe(100, 100, 100, 400) Returns:
`appium.webdriver.webelement.WebElement`
"""

start_x:开始坐标 x 轴

start_y:开始坐标 y 轴

end_x:结束坐标 x 轴

end_y:结束坐标 y 轴

duration:开始坐标移动到结束坐标的时间,默认 None

坐标原点位于屏幕左上角

一段简单代码:

from appium import webdriver

desired_caps = {
'platformName': 'Android',
'deviceName': '192.168.41.101:5555',
'platformVersion': '9.0',
# apk包名
'appPackage': 'com.gem.tastyfood',
# apk的launcherActivity
'appActivity': 'com.gem.tastyfood.LaunchActivity'
} if __name__=='__main__':
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
x = driver.get_window_size()["width"]
y = driver.get_window_size()["height"]
#向左滑动
driver.swipe(x*0.9,y*0.5,x*0.1,y*0.5,duration=2000)

可以将 左滑、右滑、上滑、下滑 写成方法,方便调用:

from appium import webdriver

desired_caps = {
'platformName': 'Android',
'deviceName': '192.168.41.101:5555',
'platformVersion': '9.0',
# apk包名
'appPackage': 'com.gem.tastyfood',
# apk的launcherActivity
'appActivity': 'com.gem.tastyfood.LaunchActivity'
} # 向左滑动。y轴保持不变,X轴:由大变小
def swipe_left(driver,star_x=0.9,stop_x=0.1,duration=2000):
x1 = int(x*star_x)
y1 = int(y*0.5)
x2 = int(x*stop_x)
y2 = int(y*0.5)
driver.swipe(x1,y1,x2,y2,duration) # 向右滑动。y轴保持不变,X轴:由小变大
def swipe_right(driver,star_x=0.1,stop_x=0.9,duration=2000):
x1 = int(x*star_x)
y1 = int(y*0.5)
x2 = int(x*stop_x)
y2 = int(y*0.5)
driver.swipe(x1,y1,x2,y2,duration) # 向上滑动。x轴保持不变,y轴:由大变小
def swipe_up(driver,star_y=0.9,stop_y=0.1,duration=2000):
x1 = int(x*0.5)
y1 = int(y*star_y)
x2 = int(x*0.5)
y2 = int(y*stop_y)
driver.swipe(x1,y1,x2,y2,duration) # 向下滑动。x轴保持不变,y轴:由小变大
def swipe_down(driver,star_y=0.1,stop_y=0.9,duration=2000):
x1 = int(x*0.5)
y1 = int(y*star_y)
x2 = int(x*0.5)
y2 = int(y*stop_y)
driver.swipe(x1,y1,x2,y2,duration) if __name__=='__main__':
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
x = driver.get_window_size()["width"]
y = driver.get_window_size()["height"]
swipe_left(driver)
swipe_right(driver)
swipe_up(driver)
swipe_down(driver)

Appium swipe实现屏幕滑动的更多相关文章

  1. APPium+Python+iOS屏幕滑动方法对比

    最近在学习appium自动化,对iOS手机进行滑动操作进行总结: 1.mobile:scroll;该方法在实际使用调用时,会滚动2次.执行时间很长. 向下滚动整个屏幕driver.execute_sc ...

  2. appium(屏幕滑动)

    class handleswipe(): """ 屏幕滑动操作 """ def __init__(self, driver, functio ...

  3. Appium左右、上下滑动(Java)

    网上很多文章都说用swipe来左右滑动,你把代码一贴,结果报错,看半天,原来是java-client中swipe早就被废除了!!!下面介绍一种Java写法来左右上下滑动: 首先,创建一个Swipe类 ...

  4. 【Android Developers Training】 70. 使用ViewPager实现屏幕滑动

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  5. Appium 点击屏幕

    由于版本变更,appium 点击屏幕方法已经改变, TouchAction action = new TouchAction(driver); Duration duration = Duration ...

  6. python+Appium自动化:app滑动操作swipe

    swipe Appium使用滑动操作用到了swipe方法,定义如下: swipe(self, start_x, start_y, end_x, end_y, duration=None) 从一个点滑动 ...

  7. 使用python实现appium的屏幕滑动

    前些日子写一个滑动手机页面的小脚本,看到大家给的内容都是swipe方法,这里对swipe方法做一个小介绍: Swipe(int start x,int start y,int end x,int y, ...

  8. 【转】使用python实现appium的屏幕滑动

    前些日子写一个滑动手机页面的小脚本,看到大家给的内容都是swipe方法,这里对swipe方法做一个小介绍: Swipe(int start x,int start y,int end x,int y, ...

  9. Appium Android 屏幕滑动

随机推荐

  1. selenium元素定位方法之轴定位

    一.轴运算名称 ancestor:祖先结点(包括父结点) parent:父结点 preceding:当前元素节点标签之前的所有结点(html页面先后顺序) preceding-sibling:当前元素 ...

  2. GO的执行原理以及GO命令

    Go的执行原理以及Go的命令 一.Go的源码文件 Go 的源码文件分类: 如上图,分为三类: 1.命令源码文件: 声明自己属于 main 代码包.包含无参数声明和结果声明的 main 函数. 命令源码 ...

  3. requests库的使用、安装及方法的简单介绍

    requests库的使用.安装及方法的简单介绍 1.requests库的概述 requests库是一个简洁且简单的处理HTTP请求的第三方库,是公认的最好获得第三方信息的库. requests库更多信 ...

  4. EF-入门操作

    EntityFramework Core 理解 DbContext :数据库 DbSet: 数据库表 Model : 数据行 IQueryable<Model> 查询结果集合 Lamada ...

  5. RandomAccessFile实现简易记事本工具操作

    package seday03; import java.io.IOException; import java.io.RandomAccessFile; import java.util.Scann ...

  6. 前端开发JS——jQuery常用方法

    jQuery基础(三)- 事件篇   1.jQuery鼠标事件之click与dbclick事件 click方法用于监听用户单击操作,dbclick方法用于监听用户双击操作,这两个方法用法及其类似,所以 ...

  7. Docker关于镜像、容器的基本命令

    镜像 1.获取镜像 docker pull 服务器:端口/仓库名称:镜像 ➜ ~ docker pull python Using default tag: latest 2.查看镜像信息 列出本机所 ...

  8. iOS安全攻防(一):Hack必备的命令与工具

    转自:http://blog.csdn.net/yiyaaixuexi/article/details/8288077 你的应用正在被其他对手反向工程.跟踪和操作!你的应用是否依旧裸奔豪不防御? 郑重 ...

  9. 74HC245引脚定义 使用方法

    典型的CMOS型三态缓冲门电路,八路信号收发器. 由于单片机或CPU的数据/地址/控制总线端口都有一定的负载能力,如果负载超过其负载能力,一般应加驱动器. 主要应用于大屏显示 引脚定义 DIR:方向控 ...

  10. ElasticSearch安装及运行的坑

    一.确认centos系统是为64位的,x86的不可以安装 1. 下载elasticsearch包 2. 用 tar -zxvf 解压包 3. 增加一个elk用户,elasticsearch7不可用ro ...