網站首頁 編程語言 正文
首先從appium庫里面導入webdriver,然后webdriver.Remote()聲明driver對象。
想要使用TouchAction,必須要創建TouchAction對象,通過對象調用想要執行的手勢,通過perform()執行動作。
#導入TouchAction from appium.webdriver.common.touch_action import TouchAction
1、最常見的點擊方式click()方法?
driver.find_element_by_id("com.android.settings:id/search").click()
2、手指輕敲屏幕操作tap()方法
tap(element,x,y)可以通過元素定位的方式敲擊,也可以通過元素坐標的方式。
# 通過元素定位方式敲擊屏幕 el = driver.find_element_by_xpath("http://*[contains(@text,'WLAN')]") TouchAction(driver).tap(el).perform() #perform()方法發送命令到服務器執行操作 # 通過坐標方式敲擊屏幕,元素坐標:x=149,y=324 TouchAction(driver).tap(x=149,y=324).perform()
3、手指按下操作press()方法
press(elemnet,x,y)可以通過元素定位的方式按下,也可以通過元素坐標的方式按下。
release()方法為結束動作,手指按下之后離開屏幕。
# 通過元素定位方式按下屏幕 el = driver.find_element_by_xpath("http://*[contains(@text,'WLAN')]") TouchAction(driver).press(el).release().perform() #通過坐標的方式,元素坐標x=149,y=324 TouchAction(driver).press(147,324).release().perform()
4、模擬手指長按操作long_press()方法
長按相對于按下來說增加了按下的時間長短,所以參數多了一個duration單位是毫秒。
long_press(elemnet,x,y,duration)也是可以通過元素定位的方式按下,也可以通過元素坐標的方式按下。
? ? el =driver.find_element_by_id("android:id/title") ? ? ?# 通過元素定位方式長按元素 ? ??? ?TouchAction(driver).long_press(el,duration=5000).release().perform() ? ? ?# 通過坐標方式長按元素,WiredSSID坐標:x=770,y=667 ? ? ?#wait(5000)等待五秒 ? ? ?# 添加等待(有長按X效果)/不添加等待(無長按效果) ? ? ?TouchAction(driver).long_press(x=770,y=667,duration=5000).release().perform()
原文鏈接:https://blog.csdn.net/haobashenmegui/article/details/103992795
相關推薦
- 2022-09-15 c語言如何實現兩數之和_C 語言
- 2022-04-09 Python中變量的作用域詳解_python
- 2023-12-24 http中的get和post方法的區別
- 2022-11-07 Python運算符之Inplace運算符的使用教程_python
- 2023-02-12 Python取出字典中的值的實現_python
- 2023-02-15 刪除docker中沒有被使用的數據卷volume_docker
- 2023-01-13 Go?cobra庫使用教程_Golang
- 2023-01-17 Linux?ps命令詳解及Linux查看進程的操作方法_linux shell
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支