zoukankan      html  css  js  c++  java
  • Appium自动化——之操作手机按键

    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

  • 相关阅读:
    ubuntu下Nodic开发环境搭建
    usb_modeswitch移植
    STM32F4编程手册学习2_内存模型
    STM32F4 编程手册学习1_编程模型
    ARM架构中的程序执行与调用
    锲形文字 数字
    疑问
    lisp 题目
    面试官在面试时让我去破解一个软件,我成功了
    php CI ip限制
  • 原文地址:https://www.cnblogs.com/htx18/p/11905768.html
Copyright © 2011-2022 走看看