appium滑动操作(向上、向下、向左、向右)
appium滑动操作(向上滑动、向下滑动、向左滑动、向右滑动)
测试app:今日头条apk
测试设备:夜游神模拟器
代码如下:
先用x、y获取当前的width和height
def getSize(): #获取当前的width和height的x、y的值
x = driver.get_window_size()['width'] #width为x坐标
y = driver.get_window_size()['height'] #height为y坐标
return (x, y)
屏幕向上滑动
def swipeUp(t): #当前向上滑动swipeup
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.75)
y2 = int(l[1] * 0.25)
driver.swipe(x1, y1, x1, y2,500) #设置时间为500
swipeUp(9000) #向上滑动9000
屏幕向左滑动
def swipLeft(t): #当前向左进行滑动swipleft
l=getSize()
x1=int(l[0]*0.75)
y1=int(l[1]*0.5)
x2=int(l[0]*0.05)
driver.swipe(x1,y1,x2,y1,500)
swipLeft(3000) #向左滑行3000
屏幕向右滑动
def swipRight(t): #向右滑行swipright
l=getSize()
x1=int(l[0]*0.05)
y1=int(l[1]*0.5)
x2=int(l[0]*0.75)
driver.swipe(x1,y1,x2,y1,500)
swipRight(3000) #向右滑行3000,回到初始位置
屏幕向下滑动
def swipeDown(t): #向下滑动swipedown
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.25)
y2 = int(l[1] * 0.75)
driver.swipe(x1, y1, x1, y2,500)
swipeDown(10000) #向下滑动10000
测试今日头条向上、向下、向左、向右滑动操作完整代码
#coding=utf-8
from appium import webdriver
import time
desired_caps={
'platformName':'Android',
'deviceName':'127.0.0.1:62001', #模拟器名称
'platformVersion':'4.4.2', #安卓版本
'appPackage':'com.ss.android.article.news', #当前apk的包名
'appActivity':'com.ss.android.article.news.activity.SplashBadgeActivity' #当前apk的appActivity
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(10) def getSize(): #获取当前的width和height的x、y的值
x = driver.get_window_size()['width'] #width为x坐标
y = driver.get_window_size()['height'] #height为y坐标
return (x, y) def swipeUp(t): #当前向上滑动swipeup
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.75)
y2 = int(l[1] * 0.25)
driver.swipe(x1, y1, x1, y2,500) #设置时间为500
swipeUp(9000) #向上滑动9000 def swipLeft(t): #当前向左进行滑动swipleft
l=getSize()
x1=int(l[0]*0.75)
y1=int(l[1]*0.5)
x2=int(l[0]*0.05)
driver.swipe(x1,y1,x2,y1,500)
swipLeft(3000) #向左滑行3000 def swipeDown(t): #向下滑动swipedown
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.25)
y2 = int(l[1] * 0.75)
driver.swipe(x1, y1, x1, y2,500)
swipeDown(10000) #向下滑动10000 def swipRight(t): #向右滑行swipright
l=getSize()
x1=int(l[0]*0.05)
y1=int(l[1]*0.5)
x2=int(l[0]*0.75)
driver.swipe(x1,y1,x2,y1,500)
swipRight(3000) #向右滑行3000,回到初始位置
time.sleep(20)
driver.quit() #退出当前的app
appium滑动操作(向上、向下、向左、向右)的更多相关文章
- js实现Mac触摸板双指事件(上、下、左、右、放大、缩小)
前言 这几天在修复一个web问题时,需要捕获Mac触摸板双指事件(上.下.左.右.放大.缩小),但发现并没有现成的轮子,还是要自己造. 例如:jquery.mousewheel.js(添加跨浏览器的鼠 ...
- 硅谷新闻4--解决页签手指按下从左到右滑动的bug
有一种方法可以阻止父层的View截获touch事件,就是调用 getParent().requestDisallowInterceptTouchEvent(true);方法.一旦底层View收到tou ...
- ViewPager 滑动一半的判断方法以及左滑右滑判断
做项目的时候,会碰到用viewpager + fragments去实现多页滑动.有些时候需要完成:界面在滑动到一半或是一半以上的时候,需要把title之类的切换到下一个页面.这个时候仅仅依赖Viewp ...
- java编写一个可以上、下、左、右移动的坦克
唉,本人学习进度缓慢,但依然会坚持不懈!有感兴趣的朋友可以在下面留言. 源代码献上: /* * 画出我的坦克,使他可以上下左右移动 */package com.test4; import javax. ...
- Unity3D_(游戏)控制物体的上、下、左、右移动
通过键盘上↑.↓.←.→实现对物体的控制 using System.Collections; using System.Collections.Generic; using UnityEngine; ...
- 在Button上、下、左、右位置加入图片和文字
转载请注明出处:http://blog.csdn.net/droyon/article/details/37564419 非常多人有如标题所述的需求,并且大多数人採用了自己定义组件攻克了需求,事实上还 ...
- Python Appium 滑动、点击等操作
Python Appium 滑动.点击等操作 1.手机滑动-swipe # FileName : Tmall_App.py # Author : Adil # DateTime : 2018/3/25 ...
- python+Appium自动化:app滑动操作swipe
swipe Appium使用滑动操作用到了swipe方法,定义如下: swipe(self, start_x, start_y, end_x, end_y, duration=None) 从一个点滑动 ...
- Atitit.获得向上向下左的右的邻居的方法 软键盘的设计..
Atitit.获得向上向下左的右的邻居的方法 软键盘的设计.. Left right可以直接使用next prev.. Up down可以使用pix 判断...获得next element的posit ...
随机推荐
- Mysql Order By 字符串排序,mysql 字符串order by
Mysql Order By 字符串排序,mysql 字符串order by ============================== ©Copyright 蕃薯耀 2017年9月30日 http ...
- Hadoop问题:Incorrect configuration: namenode address dfs.namenode.rpc-address is not configured
问题描述:Incorrect configuration: namenode address dfs.namenode.rpc-address is not configured 问题分析:core- ...
- 配置shiro错误
在web配置工程中配置shiro,如果启动Tomcat,报错:org.apache.shiro.web.config.WebIniSecurityManagerFactory.setDefaults ...
- Spring-AOP标签scoped-proxy
<aop:scoped-proxy/>介绍: Spring的Bean是有scope属性的,表示bean的生存周期.scope的值有prototype.singleton.session.r ...
- CSS深入理解学习笔记之float
1.float的历史 float设计的初衷仅仅是为了文字环绕效果. 示例代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ...
- 02_HTML5+CSS详解第三天
WebStorage简单的网页留言板用到的函数有3个1.saveStorage函数使用"new Date().getTime()"语句来获取当前的日期和时间戳,然后使用localS ...
- curl错误码说明
1.得到错误码 $errno=curl_errno($ch); if($errno!=0){ -- } 2.错误码说明 <?php return [ '1'=>'CURLE_UNSUPPO ...
- 【转】CentOS 6.3(x86_32)下安装Oracle 10g R2
一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...
- MathUtils
package com.yqw.java.util;/** * 数字转换工具 */public class MathUtils { /** * short转byte */ ...
- ABP官方文档翻译 7.3 Quartz集成
Quartz集成 介绍 安装 创建Jobs 计划安排Jobs 更多 介绍 Quartz是一个全功能的.开源的job计划安排系统,可以用在小的apps也可以用于大型的企业系统.Abp.Quartz包简化 ...