天天看點

Python - Appuim 2. 常用API 以及 selenium 版本更新引發的問題

元素定位

打開

%ANDROID_HOME%\tools\uiautomatorviewer.bat      

通過uiautomator 可以定位元素

API 使用情況如下

text -> findElementByName
resource-id -> findElementById
class -> findElementByClassName
content-desc -> findElementByAccessibilityId      

滾動

self.driver.scroll(els[10], els[1])      

拖拽

drag_and_drop(els[10], els[3])      

滑動

swipe(100, 750, 100, 100)      

點選

self.driver.tap([(100, 750)])      

快速滑動

flick(100, 750, 100, 100)      

等待頁面加載完成

wait_activity(self, activity -> 頁面, timeout, interval=1):      

selenium 版本可能導緻的問題

Message: Parameters were incorrect. We wanted {“required”:[“value”]} and you sent [“text”,”sessionId”,”id”,”value”]      

解決方法

pip uninstall selenium
pip install selenium==3.3.1      

根據PID 查找程序占用的端口

netstat -ano | grep PID      

adb 連接配接 夜神模拟器

adb connect 127.0.0.1:62001      

一些國産模拟器需要的端口

Python - Appuim 2. 常用API 以及 selenium 版本更新引發的問題

繼續閱讀