Appium automated operation of the phone keys

By briefly operating appium simulation system key, such as the return key, Home key, a volume key and the like. To operate the analog button keyevent method used to obtain the following parameters

keyevent(keycode, metastate=None)

keycode: code devices to a key, the key code, the entity corresponding to the encoding key

 metastate: defaults do not fill

demo operation of the volume key as follows:

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"
               } 

# Statement driver objects 
driver webdriver.Remote = ( ' http://127.0.0.1:4723/wd/hub ' , desired_caps)
 # TODO pressing volume change 
for I in Range (. 6 ): 
    driver.keyevent ( 25 ) 

Time .sleep ( . 1 )
 # return key 
driver.keyevent (. 4 ) 

# driver.long_press_keycode ()

 

Common key list:

 

Guess you like

Origin www.cnblogs.com/xiamaojjie/p/11515680.html