appium java 点击事件_Appium行为事件处理

1.查看源码语法,起点和终点四个坐标参数,duration是滑动屏幕持续的时间,时间越短速度越快。默认为None可不填,一般设置500-1000毫秒比较合适。

swipe(self, start_x, start_y, end_x, end_y, duration=None)

Swipe from one point to another point, for an optional duration.

从一个点滑动到另外一个点,duration是持续时间

:Args:

- start_x - 开始滑动的x坐标 -

start_y - 开始滑动的y坐标 -

end_x - 结束点x坐标 -

end_y - 结束点y坐标 -

duration - 持续时间,单位毫秒

:Usage:

driver.swipe(100, 100, 100, 400)

2.手机从左上角开始为0,横着的是x轴,竖着的是y轴

获取坐标

# coding:utf-8 from appium import webdriver

des_leidian = {

"platformName": "Android",

"deviceName": "CLB0219103005568",

"platformVersion": "9",

"appPackage": "com.mmc.feelsowarm",

"appActivity": "com.mmc.feelsowarm.WelcomeActivity",

"noReset": True

}

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

# 获取屏幕的size

size = driver.get_window_size()

# 屏幕宽度width

print(size['width'])

# 屏幕高度width

print(size['height'])

运行结果:

{u'width': 720, u'height': 1280}

720

1280

封装滑动方法

1.把上下左右四种常用的滑动方法封装,这样以后想滑动屏幕时候就能直接调用了

参数1:driver

参数2:t是持续时间

参数3:滑动次数

68f724bad5a33d9a9f6bd2ca7369ecb7.png

def swipe_up(self, n=1):

'''

往上滑

:param driver:

:return: None

'''

x1 = self.fenbianlv['width']/2

y1 = self.fenbianlv['height'] * 3 /4

x2 = self.fenbianlv['width']/2

y2 = self.fenbianlv['height'] /4

for i in range(n):

self.driver.swipe(x1, y1, x2, y2, 500)

def swipe_down(self, n=1):

'''

往下滑

:param driver:

:return: None

'''

x1 = self.fenbianlv['width']/2

y1 = self.fenbianlv['height'] /4

x2 = self.fenbianlv['width']/2

y2 = self.fenbianlv['height'] * 3 /4

for i in range(n):

self.driver.swipe(x1, y1, x2, y2, 500)

def swipe_left(self, n=1):

'''

往左滑

:param driver:

:return: None

'''

x1 = self.fenbianlv['width']*3/4

y1 = self.fenbianlv['height'] /2

x2 = self.fenbianlv['width']/4

y2 = self.fenbianlv['height'] /2

for i in range(n):

self.driver.swipe(x1, y1, x2, y2, 500)

def swipe_right(self, n=1):

'''

往右滑

:param driver:

:return: None

'''

x1 = self.fenbianlv['width']/4

y1 = self.fenbianlv['height'] /2

x2 = self.fenbianlv['width']*3 /4

y2 = self.fenbianlv['height'] /2

for i in range(n):

self.driver.swipe(x1, y1, x2, y2, 500)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值