appium之Context切换
原文地址http://blog.csdn.net/Mandypan/article/details/51396302
Context切换
driver.getContextHandles();//获取页面的context
driver.context("WEBVIEW");
driver.context("NATIVEAPP");
eg:
public void GetResource_Android(){
set<String> contextSet=wd.getContextHandles();
for(String context : contextSet){
System.out.println(context);
}
}
Context切换
driver.getContextHandles();
driver.context("WEBVIEW");
driver.context("NAVTIVEAPP");
查看当前所有的窗口:
Set<String> contextNames=driver.getContextHandles();
System.out.print(contextNames);
切换到Webview
<pre name="code"class="java">driver.context("WEBVIEW");
driver.findElementByID("wd");
切换到NativeAPP
<pre name="code" class="java">driver.context("NATIVE_APP");
demo
/**
* Switch to NATIVE_APP or WEBVIEW
* @param sWindow window name
*/
private void switchToWindow(String sWindow) {
LogManager.getLogger(this.getClass()).info("Swith to window: " + sWindow);
Set<String> contextNames = driver.getContextHandles();
LogManager.getLogger(this.getClass()).info("Exists windows: " + contextNames.toString());
for (String contextName : contextNames) {
if (contextName.contains(sWindow)) {
driver.context(contextName);
break;
}
}
}
switchToWindow("WEBVIEW_com.test.android");
switchToWindow("NATIVE_APP");
页面切换
String pWindUrl = driver.getCurrentUrl(); 获取当前窗口的url
//跳至新打开的窗口
if (driver.getWindowHandles().size() != 2) {fail(); }
for (String handle : driver.getWindowHandles()) {
driver.switchTo().window(handle); 遍历跳转到每一个打开的窗口
if (driver.getCurrentUrl().equals(pWindUrl)){ 如果这个窗口的url是pWindUrl则表明是当前的窗口
driver.close(); //关闭当前窗口
}
}
最新文章
- Mybatis 拦截器
- iOS NSFileManager 使用详解
- 2.2---找链表倒数第K个结点
- Python学习(22)python网络编程
- QThread 与 QObject的关系(QObject可以用于多线程,可以发送信号调用存在于其他线程的slot函数,但GUI类不可重入)
- Solr高亮与Field权重
- Android开发学习之路--NDK、JNI之初体验
- Python_range
- Vue-Router嵌套路由
- apidoc @apiGroup兼容中文
- mysql installer gentask怎么关闭
- python全栈开发 * 31知识点汇总 * 180716
- SQLServer&#160;Management&#160;Studio登录框中的“服务器名”填写
- QOpenGLFunctions的相关的使用(1)
- 关于ListBox的几个问题
- Web验证方式(4)--JWT
- 【刷题】BZOJ 1095 [ZJOI2007]Hide 捉迷藏
- VMWare Workstation 15 serial number
- Centos查看系统位数方法
- gridView删除提示框
热门文章
- yum安装的JDK的没有配置环境变量但是在/usr/bin下面都做了软链接
- 理解Java中字符流与字节流
- CentOS全自动一键安装PHP,MySQL,phpmyadmin与Nginx
- CRF++使用说明
- .NET开发相关使用工具和框架
- 2017 ACM区域赛(南宁站) 参赛流水账
- spark(1.1) mllib 源码分析(一)-卡方检验
- iOS #import和@class 区别
- Android开发:《Gradle Recipes for Android》阅读笔记(翻译)4.5——使用Android Libraries
- 让TextView的drawableLeft与文本一起居中显示