python控制手机点击_Python Appium 滑动、点击等操作

Python Appium 滑动、点击等操作

1、手机滑动-swipe

#FileName : Tmall_App.py#Author : Adil#DateTime : 2018/3/25 17:22#SoftWare : PyCharm

from appium importwebdriver

caps={}

caps['platformName'] = 'Android'caps['platformVersion'] = '6.0'caps['deviceName'] = 'N79SIV5PVCSODAQC'caps['appPackage'] = 'com.tmall.wireless'caps['appActivity'] = 'com.tmall.wireless.splash.TMSplashActivity'

#隐藏键盘

caps['unicodeKeyboard'] =True

caps['resetKeyboard'] =True

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

driver.swipe()if __name__ == '__main__':pass

查看源码

Ctrl + 鼠标右键点击 driver.swipe()

#convenience method added to Appium (NOT Selenium 3)

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 - x-coordinate at which to start

- start_y - y-coordinate at which to start

- end_x - x-coordinate at which to stop

- end_y - y-coordinate at which to stop

- duration - (optional) time to take the swipe, in ms.

:Usage:

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

#`swipe` is something like press-wait-move_to-release, which the server

#will translate into the correct action

action =TouchAction(self)

action \

.press(x=start_x, y=start_y) \

.wait(ms=duration) \

.move_to(x=end_x, y=end_y) \

.release()

action.perform()return self

查看源码语法,起点和终点四个坐标参数。 手机屏幕从左上角开始为0,向右为x轴坐标,向下为y轴坐标。

duration是滑动屏幕持续的时间,时间越短速度越快。默认为None可不填,一般设置500-1000毫秒比较合适。

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

Swipefrom one point to another point

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值