首页 > 移动平台 > 详细

Appium自动化——之操作手机按键

时间:2019-11-21 15:47:20      阅读:118      评论:0      收藏:0      [点我收藏+]

appium模拟操作安卓手机按键

APPium自动化过程中,可能会需要模拟操作手机按键,如返回键,home键,音量键等等。

要模拟按键操作得用到 keyevent方法,参数如下

keyevent(keycode, metastate=None)

metastate:默认值不用填

 

操作手机音量键和返回键的代码如下:

 1 from appium import webdriver
 2 import time
 3 from appium.webdriver.common.mobileby import MobileBy as MB
 4 from selenium.webdriver.support.wait import WebDriverWait
 5 from selenium.webdriver.support import expected_conditions as EC
 6 
 7 # 连接设备、启动APP的相关参数
 8 caps = {
 9     "platformName":"Android",   # 平台类型
10     "platformVersion":"7.1.1",  #平台版本
11     "deviceName":"SWCUJFGULNVCGIEI",    #设备名
12     "appPackage":"com.tencent.wework",   #APP的包名
13     "appActivity":"com.tencent.wework.launch.LaunchSplashActivity",  #APP的启动名
14     "noReset":"True",   #是否重置APP
15     "automationName":"UiAutomator2",
16     "noCanmandTime":"6000" ,     #超时时长
17     "chromedriverExecutable":"D:\\work\\Chromedriver\\65_67\\chromedriver.exe"
18 }
19 
20 driver = webdriver.Remote(http://127.0.0.1:4723/wd/hub, caps)
21 # 设置隐式等待
22 driver.implicitly_wait(30)
23 # 音量减
24 driver.keyevent(25)
25 time.sleep(1)
26 # 返回键
27 driver.keyevent(4)

Android的keycode键值

技术分享图片

 

官方keyevent文档
地址: https://developer.android.com/reference/android/view/KeyEvent.html

 

 

 

 

 

 

Appium自动化——之操作手机按键

原文:https://www.cnblogs.com/htx18/p/11905768.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!