Appium + python - swipe滑屏操作实例
方法一:
from appium import webdriver
from time import sleep descred_caps = {
"platformName":"Android",
"platformVersion":"5.1.1",
"deviceName":"127.0.0.1:62001",
"appPackage":"com.baidu.yuedu",
"appActivity":"com.baidu.yuedu.splash.SplashActivity",
"noRset":"true",
"unicodeKeyboard":"true",
"resetKeyboard":"true"
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",descred_caps) #获取屏幕size
size = driver.get_window_size()
print(size) #屏幕的宽度 width
print(size["width"]) #屏幕的高度 height
print(size["height"]) def swipeUp(driver,t=500,n=1):
"""向上屏幕滑动"""
x1 = size["width"] * 0.5 # x坐标
y1 = size["height"] * 0.75 # 起点 y坐标
y2 = size["height"] * 0.25 # 终点 y 坐标
for i in range(n):
driver.swipe(x1,y1,x1,y2,t) def swipeDown(driver,t=500,n=1):
"""向下屏幕滑动"""
x1 = size["width"] * 0.5 # x1 坐标
y1 = size["height"] * 0.25 # 起点y1坐标
y2 = size["height"] * 0.75 # 终点y2坐标
for i in range(n):
driver.swipe(x1,y1,x1,y2,t) def swipeLeft(driver,t=500,n=1):
"""向左屏幕滑动"""
x1 = size["width"] * 0.75 # 起点x1坐标
y1 = size["height"] * 0.5 # y1 坐标
x2 = size["width"] * 0.25 # 终点x2坐标
for i in range(n):
driver.swipe(x1,y1,x2,y1,t) def swipeRight(driver,t=500,n=1):
"""向右屏幕滑动"""
x1 = size["width"] * 0.25 #起点x1坐标
y1 = size["height"] * 0.5 # y1坐标
x2 = size["width"] * 0.75 #终点x2坐标
for i in range(n):
driver.swipe(x1,y1,x2,y1,t) if __name__ == "__main__":
print(driver.get_window_size())
sleep(5)
swipeLeft(driver, n=2)
sleep(2)
swipeRight(driver, n=2)
driver.quit() 方法二:
#!usr/bin/env python
#!coding:utf-8 from appium import webdriver
import time as t class Swipe(object):
def __init__(self,driver):
self.driver=driver @property
def width(self):
return self.driver.get_window_size()['width'] @property
def height(self):
return self.driver.get_window_size()['height'] @property
def getResolution(self):
return str(self.width)+"*"+str(self.height) @property
def set_Left_Right(self):
'''
:return: 实现从左到右滑动,滑动时X轴起点大于终点
'''
t.sleep(2)
self.driver.swipe(self.width*9/10,self.height/2,self.width/20,self.height/2,0) @property
def set_Right_Left(self):
'''
:return:实现从右到左滑动,滑动时X轴起点小于终点
'''
t.sleep(2)
self.driver.swipe(self.width/10,self.height/2,self.width*9/10,self.height/2,0) @property
def set_Up_Down(self):
'''
:return: 实现从上往下滑动,滑动时Y轴起点起点大于终点
'''
t.sleep(2)
self.driver.swipe(self.width/2,self.height*9/10,self.width/2,self.height/20,0) @property
def set_Down_Up(self):
'''
:return: 实现从下往上滑动,滑动时Y轴起点小于终点
'''
t.sleep(2)
self.driver.swipe(self.width/2,self.height/20,self.width/2,self.height*9/10,0)
Appium + python - swipe滑屏操作实例的更多相关文章
- Appium常用操作之「元素定位、swipe 滑屏操作」
坚持原创输出,点击蓝字关注我吧 作者:清菡 博客:oschina.云+社区.知乎等各大平台都有. 目录 一.打开 uiautomatorviewer 二.Appium 常用操作 1.用 layui 做 ...
- appium + Python + iOS 滑屏方法(appium版本大于1.5)
之前一直在搞android的自动化,滑动操作一直都用swipe(),比如: he1 = int(dr.get_window_size()['height'] * 0.8)he2 = int(dr.ge ...
- Python编程之列表操作实例详解【创建、使用、更新、删除】
Python编程之列表操作实例详解[创建.使用.更新.删除] 这篇文章主要介绍了Python编程之列表操作,结合实例形式分析了Python列表的创建.使用.更新.删除等实现方法与相关操作技巧,需要的朋 ...
- python 发送json数据操作实例分析 - python
文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 本文实例讲述了python 发送json数据操作.分享给大家供大家参考,具体如下: # !/usr/bin/env py ...
- Appium + python - weixin公众号操作
from appium import webdriverfrom time import sleep desired_caps = { "platformName":"A ...
- Appium + python - get_attribute获取value操作
from appium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.w ...
- Appium + python - automator定位升级版操作
# coding:utf-8 """参考博客链接:https://www.cnblogs.com/yoyoketang/p/7843819.html"" ...
- 仿iPhone滑屏操作
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <m ...
- python selenium2 有关cookie操作实例及如何绕开验证码
1.先看一下cookie是啥 cookie是访问web时服务器记录在用户本地的一系列用户信息(比如用户登录信息),以便对用户进行识别 from selenium import webdriver im ...
随机推荐
- 跳转语句(break、continue)
break语句 在switch条件语句和循环语句中都可以使用break语句.当它出现在switch条件语句中时,作用是终止某个case并跳出switch结构. 当它出现在循环语句中,作用是跳出循环语句 ...
- bootstrap table分页(前后端两种方式实现)
bootstrap table分页的两种方式: 前端分页:一次性从数据库查询所有的数据,在前端进行分页(数据量小的时候或者逻辑处理不复杂的话可以使用前端分页) 服务器分页:每次只查询当前页面加载所需要 ...
- S-HR之OSF
1):getWorkDayCount ->ArrayList data = (ArrayList) com.kingdee.shr.rpts.ctrlreport.osf.OSFExecutor ...
- Beauty of Array ZOJ - 3872(思维题)
Edward has an array A with N integers. He defines the beauty of an array as the summation of all dis ...
- Win32中 DLL、Lib 库的创建机器使用
Windows 下 的静态库和动态库 一.静态函数库(Lib) 1. 静态函数库的制作(C/C++) —— 打开新建项目,然后选中Win32项目,接着在创建项目中选择 Lib,再接着将函数.实现功能的 ...
- ubuntu 14.04 gcc/g++版本降低
Matlab 2014a支持的gcc/g++版本是4.7x,而ubuntu 14.04以及更高版本默认安装的版本都是4.8及以上,因此需要降低gcc/g++版本,方法如下: 1 安装 $ sudo a ...
- linux系统监控:记录用户操作轨迹,谁动过服务器
1.前言 我们在实际工作当中,都碰到过误操作.误删除.误修改过配置文件等等事件.对于没有堡垒机的公司来说,要在linux系统上深究到底谁做过配置文件的修改.做过误删除是很头疼的事情,特别是遇到删库跑路 ...
- nyoj_264_国王的魔镜_201311271800
国王的魔镜 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 国王有一个魔镜,可以把任何接触镜面的东西变成原来的两倍——只是,因为是镜子嘛,增加的那部 ...
- 【ACM】nyoj_14_会场安排问题_201308151955
会场安排问题时间限制:3000 ms | 内存限制:65535 KB 难度:4描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工作就是安 ...
- thymeleaf模板使用th:onclick进行传参
错误的写法: th:onclick="'javascript:editUser('+${prod.id}+');'" 正确的写法: th:onclick="'javasc ...