zoukankan      html  css  js  c++  java
  • appium自动化之对手机按键的操作

    简单说说通过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()

    常用键列表:

  • 相关阅读:
    leetcode680
    leetcode558
    leetcode840
    leetcode703
    leetcode836
    leetcode704
    leetcode849
    leetcode707
    2019-10-26-Inno-Setup-安装包脚本-Run-的-Flags-标记
    2019-8-30-C#-从零开始写-SharpDx-应用-笔刷
  • 原文地址:https://www.cnblogs.com/xiamaojjie/p/11515680.html
Copyright © 2011-2022 走看看