原文地址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(); //关闭当前窗口
      }

}

最新文章

  1. Mybatis 拦截器
  2. iOS NSFileManager 使用详解
  3. 2.2---找链表倒数第K个结点
  4. Python学习(22)python网络编程
  5. QThread 与 QObject的关系(QObject可以用于多线程,可以发送信号调用存在于其他线程的slot函数,但GUI类不可重入)
  6. Solr高亮与Field权重
  7. Android开发学习之路--NDK、JNI之初体验
  8. Python_range
  9. Vue-Router嵌套路由
  10. apidoc @apiGroup兼容中文
  11. mysql installer gentask怎么关闭
  12. python全栈开发 * 31知识点汇总 * 180716
  13. SQLServer&#160;Management&#160;Studio登录框中的“服务器名”填写
  14. QOpenGLFunctions的相关的使用(1)
  15. 关于ListBox的几个问题
  16. Web验证方式(4)--JWT
  17. 【刷题】BZOJ 1095 [ZJOI2007]Hide 捉迷藏
  18. VMWare Workstation 15 serial number
  19. Centos查看系统位数方法
  20. gridView删除提示框

热门文章

  1. yum安装的JDK的没有配置环境变量但是在/usr/bin下面都做了软链接
  2. 理解Java中字符流与字节流
  3. CentOS全自动一键安装PHP,MySQL,phpmyadmin与Nginx
  4. CRF++使用说明
  5. .NET开发相关使用工具和框架
  6. 2017 ACM区域赛(南宁站) 参赛流水账
  7. spark(1.1) mllib 源码分析(一)-卡方检验
  8. iOS #import和@class 区别
  9. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)4.5——使用Android Libraries
  10. 让TextView的drawableLeft与文本一起居中显示