webview元素定位

genymotion 模拟器:android  5.0.0 
python 2.7
appium 1.4.16.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")
二、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的定位方式
一、手机须要安装谷歌浏览器,并打开app的网址;
二、在chrome中输入chrome://inspect/#devices,此时打开app页面
三、若是点击inspect为空白窗口,在hosts文件中添加以下地址:
61.91.161.217 chrome-devtools-frontend.appspot.com
61.91.161.217 chrometophone.appspot.com
四、而后cmd中输入命令:ipconfig /flushdns   刷新dns配置,再打开inspect
五、点击放大镜符号能够定位元素
三、此时可获取到webview的url,直接在chrome打开也可进行元素定位
相关文章
相关标签/搜索