简单说说通过appium模拟系统按键的操作,如返回键,home键,音量键等等。要模拟按键操作得用到 keyevent方法,参数如下
keyevent(keycode, metastate=None)
keycode:发送给设备的关键代码,关键代码,指的是实体按键对应的编码
metastate:默认值不用填
操作音量键的demo如下:
from appium import webdriver import time desired_caps = { "platformName":"Android", "platformVersion":"5.1", "deviceName":"127.0.0.1:62001", "appPackage":"com.android.settings", "appActivity":".Settings" } # 声明driver对象 driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘,desired_caps) # todo 按压音量增减 for i in range(6): driver.keyevent(25) time.sleep(1) # 返回键 driver.keyevent(4) #driver.long_press_keycode()
常用键列表:
原文地址:https://www.cnblogs.com/xiamaojjie/p/11515680.html
时间: 2024-11-06 09:50:09