APPium自动化过程中,可能会需要模拟操作手机按键,如返回键,home键,音量键等等。
要模拟按键操作得用到 keyevent方法,参数如下
keyevent(keycode, metastate=None)
metastate:默认值不用填
操作手机音量键和返回键的代码如下:
from appium import webdriver
import time
from appium.webdriver.common.mobileby import MobileBy as MB
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 连接设备、启动APP的相关参数
caps = {
"platformName":"Android", # 平台类型
"platformVersion":"7.1.1", #平台版本
"deviceName":"SWCUJFGULNVCGIEI", #设备名
"appPackage":"com.tencent.wework", #APP的包名
"appActivity":"com.tencent.wework.launch.LaunchSplashActivity", #APP的启动名
"noReset":"True", #是否重置APP
"automationName":"UiAutomator2",
"noCanmandTime":"6000" , #超时时长
"chromedriverExecutable":"D:\\work\\Chromedriver\\65_67\\chromedriver.exe"
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', caps)
# 设置隐式等待
driver.implicitly_wait(30)
# 音量减
driver.keyevent(25)
time.sleep(1)
# 返回键
driver.keyevent(4)
Android的keycode键值
官方keyevent文档
地址: https://developer.android.com/reference/android/view/KeyEvent.html
转载链接:https://www.cnblogs.com/htx18/p/11905768.html
标签:webdriver,appium,keyevent,安卓,按键,import,com,APP From: https://www.cnblogs.com/simon1993/p/18006425