在 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. clientHeight—scrollHeight—offsetHeight三者的区别

    clientHeight,scrollHeight,offsetHeight 这三个dom属性有时让人觉得相似但又不相似 以前对它们的理解也有一些模糊,现在总结一下,方便以后复习 clientHeig ...

  2. KeContextToKframes函数逆向

    在逆向_KiRaiseException(之后紧接着就是派发KiDispatchException)函数时,遇到一个 KeContextToKframes 函数,表面意思将CONTEXT转换为 TRA ...

  3. MySQL(7)---存储过程

    Mysql(7)---存储过程 存储过程接下来会有三篇相关博客 第一篇存储过程常用语法. 第二篇存储过程中的游标. 第三篇单独讲一个实际开发过程中复杂的真实的案例. 一.概述 1.什么是存储过程 概述 ...

  4. C# delegate multicast single delegate

    using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serializatio ...

  5. HTTP Error 500.35 - ANCM Multiple In-Process Applications in same Process

    vs2019   win10 情况:报错 HTTP Error 500.35 - ANCM Multiple In-Process Applications in same Process 微软官方解 ...

  6. Python【day 15-3】函数部分

    '''''' ''' 一.函数 1.函数定义 对功能或者动作的封装 在类中定义,就是方法 在类之外定义,就是函数 2.函数写法 1.定义或者申明函数 def 函数名(形参列表): 函数体(return ...

  7. DevExpress的下拉框控件ComboBoxEdit控件的使用

    场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...

  8. 在CAD中进行圆角标注的方法

    在CAD中,大家经常都用听到CAD标注.那其实在CAD中进行标注也是比较常见的工作,CAD标注有文字标注,数值标注等一些标注的方式.下面要来说的就是在CAD中给圆角图形标注的方法,具体操作步骤如下: ...

  9. Oracle 12C Win 10 安装 应用 总结

    安装参考 https://www.cnblogs.com/onezg/p/8768597.html 我当时安装的是Oracle 12c Release 1(Version 12.1.0.1.0,64位 ...

  10. uni-app条件编译:#ifdef #ifndef #endif

    语法: // #ifdef %PLATFORM% 这些代码只在该平台编译 // #endif #ifdef :      if defined  仅在某个平台编译 #ifndef :     if n ...