竹竹云

导航

webview元素定位

genymotion 模拟器:android  5.0.0 
python 2.7
appium 1.4.16.1
1、app原生元素定位(常用)
driver.find_element_by_id(“resourse-id”)
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.contexts for context in contexts:     print context
问题3):切换到webview模式
driver.switch_to.context("WEBVIEW ")
问题4):切换回原生NATIVE_APP
driver.switch_to().context("NATIVE_APP")
问题5):webview的定位方式
1、手机需要安装谷歌浏览器,并打开app的网址;
2、在chrome中输入chrome://inspect/#devices,此时打开app页面
3、如果点击inspect为空白窗口,在hosts文件中添加如下地址:
61.91.161.217 chrome-devtools-frontend.appspot.com
61.91.161.217 chrometophone.appspot.com
4、然后cmd中输入命令:ipconfig /flushdns   刷新dns配置,再打开inspect
5、点击放大镜符号可以定位元素
3、此时可获取到webview的url,直接在chrome打开也可进行元素定位

posted on 2019-07-16 12:58  竹竹云  阅读(149)  评论(0编辑  收藏  举报