展開全部
genymotion 模擬器:android 5.0.0
python 2.7
appium 1.4.16.1
1、app原生元素定位(常用)
driver.find_element_by_id(“resourse-id”32313133353236313431303231363533e59b9ee7ad9431333363393662)
driver.find_element_by_name(“text”)
driver.find_element_class_name(“class”)
driver._find_element_by_accessibility_id("content-desc")
2、android+python+webview頁面的定位
問題1):driver.contexts 的結果只有NATIVE_APP,無WEBVIEW
需要開發人員在對應的activity下增加代碼,重新打包,開啟webview遠程調試的開關,且只針對android4.4及以上有用
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
this.appView.setWebContentsDebuggingEnabled(true);
}
問題2):獲取webview的名字
contexts = .driver.contextsfor context in contexts:
print context
問題3):切換到webview模式
driver.switch_to.context("WEBVIEW ")
問題4):切換回原生NATIVE_APP
driver.switch_to().context("NATIVE_APP")
問題5):webview的定位方式
1、在chrome中輸入chrome://inspect/#devices,此時打開app頁面
2、如果點擊inspect為空白窗口,在hosts文件中添加如下地址:
61.91.161.217 chrome-devtools-frontend.appspot.com
61.91.161.217 chrometophone.appspot.com
3、然后cmd中輸入命令:ipconfig /flushdns 刷新dns配置,再打開inspect
4、點擊放大鏡符號可以定位元素
3、此時可獲取到webview的url,直接在chrome打開也可進行元素定位