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 ...
随机推荐
- Django 更新字段
Django在1.7以后的版本提供数据迁移命令,用来在修改模型中的字段,更新到数据库 1. python manager.py makemigrations 命令用来创建迁移文件版本的 2. pyth ...
- (转)Struts2的拦截器
http://blog.csdn.net/yerenyuan_pku/article/details/68648101 Struts2的拦截器 拦截器的概述 拦截器,在AOP(Aspect-Orien ...
- Escaping Closures 两点:本质是生命周期标示符
1.block需要(拷贝)保存: 2.block引用的环境变量需要处理. 相当于oc中的copy block. Escaping Closures A closure is said to escap ...
- NBXplorer的配置
首先,必须安装bitcoin core bitcoin core启动时,会提示你定义数据存放目录,在数据存放目录下,找到bitcoin.conf文件,并填写内容: server=1rpcuser=rp ...
- .net core 使用 textSharp生成pdf
引入Nuget包 using iTextSharp.text; using iTextSharp.text.pdf; using System; using System.IO; namespace ...
- element select下拉框绑定number类型
vue 开发中element-ui库的switch开关绑定number类型数据不成功问题 解决方法
- Django - ORM实现用户登陆
1.路由分发cmdb(app)下urls.py中,建立url与函数对应关系 2.login.html代码: 3.views.py中,login函数,确认是否登陆成功 备注:从前端 获取用户名,密码,在 ...
- LDAP个人理解
在新的公司办公,所有的后台系统或文档系统都公用一个LDAP账号. 接触到这个新名词,就查了一下,谈谈个人理解: LDAP是个协议, 简单地说,可以把LDAP服务理解为一套存放你账户密码的数据库系统.市 ...
- CodeForces 580B(尺取法)
Kefa and Company 题意:Kefa这个人要去吃饭,他要邀请一些朋友一起去,他的每个朋友有两个属性金钱和关系度,要求邀请的人里边任意两个人之间的金钱差的绝对值不大于d:求被邀请的所有朋友的 ...
- 使用Flask+uWsgi的方式部署一个blog网站
本文参考以下文章:https://www.yukunweb.com/2017/12/ubuntu-nginx-uwsgi-flask-app/ 需要学习的地方 nginx+uwsgi部署flask应用 ...