Appium自动化——之操作手机按键
生活随笔
收集整理的這篇文章主要介紹了
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
總結
以上是生活随笔為你收集整理的Appium自动化——之操作手机按键的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php如何设置脚本最大执行时间
- 下一篇: 西门子Step7安装和入门初步