在 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. Dubbo从入门到实战:实战篇

    一.加入 zookeeper 作为注册中心 在前面的案例中,我们没有使用任何的注册中心,而是用一种直连的方式进行的.但是,实际上很多时候,我们都是使用 dubbo + zookeeper 的方式,使用 ...

  2. C# copy files from source directory to destination file and rename repeated files and does not override

    static void CopyFiles() { string sourceDir = @"D:\C\ll"; string destDir = @"D:\LL&quo ...

  3. Java生鲜电商平台-微服务架构概述

    Java生鲜电商平台-微服务架构概述 单体架构存在的问题 在传统的软件技术架构系统中,基本上将业务功能集中在单一应用内,或者是单一进程中.尽管现代化的软件架构理论以及设计原则已推广多年,但实际技术衍化 ...

  4. C#如何将DataTable中的列名复制到另一个DataTable

    C#如何将DataTable中的列名复制到另一个DataTable? 仅复制列名,不复制列下的数据: var newDt = new DataTable(); newDt = oldDataTable ...

  5. Dynamics 365利用HTML页面创建实体记录并同步上传附件

    我是微软Dynamcis 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...

  6. 微信语音短消息amr文件转WAV

    - amr说明 - 转WAV程序 我对SILK编码库稍作修改,编译了一个Windows下可直接将SILK V3编码转换为WAV格式,并支持原生的微信语音短消息amr文件的版本,提供给大家使用,压缩包( ...

  7. idea中git标签(tag)的创建与使用

    1.什么是标签 通常,发布一个版本时,会在版本库中打一个标签(tag),这样,就唯一确定了打标签时刻的版本.将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来. 所以,标签也是 ...

  8. Spark的Monitoring

    一.启动历史页面监控配置: $ vi spark-defaults.conf spark.eventLog.enabled true spark.eventLog.dir hdfs://hadoop0 ...

  9. Scala开发问题汇总

    1.JDK版本问题 Error:java.lang.VerifyError: Uninitialized Exception Details: Location: scala/collection/i ...

  10. 2018年最新Java面试题及答案整理

    基础篇 基本功 面向对象特征 封装,继承,多态和抽象 封装封装给对象提供了隐藏内部特性和行为的能力.对象提供一些能被其他对象访问的方法来改变它内部的数据.在 Java 当中,有 3 种修饰符: pub ...