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

}

appium之Context切换的更多相关文章

  1. Appium,AirTest切换使用时,appium罢工之坑(1)

    由于一些元素不能定位,所以最近项目引用了Airtest 问题场景: case的开始使用appium,case执行过程中,切换到airtest操作元素,待执行完airtest相关步骤之后,后续使用app ...

  2. appium+python自动化42-微信公众号 (可能以后会遇到也遇到切换不了webview的问题 记录再此 还没试)

    前言 本篇介绍如何在微信公众号上自动化测试,以操作我的个人公众号:yoyoketang为例,没关注的,先微信关注了,再跟着操作 环境准备:python 3.6appium 1.7以上版本微信6.6.6 ...

  3. Appium 客户端库 API

    ## Appium 客户端库 Appium 有对应以下语言的客户端库: 语言 | 代码 :--|--:[Ruby][rubygems] | [GitHub](https://github.com/ap ...

  4. 【转】NO.3、python+appium+ios,遍历真机元素,得到webview

    pyhton+appium+iOS,遍历真机webview.是遍历真机的webview,遍历模拟器的webview请另寻方法. 1.mac上安装ios_webkit_debug_proxy 命令:br ...

  5. Appium 客户端类库

    Appium 支持以下语言的客户端类库: 语言 Ruby Python Java JavaScript PHP C# Objective-C 锁定注意,一些方法类似 endTestCoverage() ...

  6. (转载)中文Appium API 文档

    该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...

  7. appium+python自动化42-微信公众号

    前言 本篇介绍如何在微信公众号上自动化测试,以操作我的个人公众号:yoyoketang为例,没关注的,先微信关注了,再跟着操作 环境准备: python 3.6 appium 1.7以上版本 微信6. ...

  8. 中文Appium API 文档

    该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...

  9. appium自动化测试(三)

    一. 层级定位和list 先通过find_element_by_XXX找到父级元素webelement,再通过webelement.find_element_by_XXX寻找子元素 二. 滑动屏幕 滑 ...

随机推荐

  1. 集群下使用redis统一session处理

    pom依赖(快照版): <dependency> <groupId>org.springframework.session</groupId> <artifa ...

  2. Deep3d研究

    如何使用CNN将视频从2D到3D进行自动转换 http://www.sohu.com/a/128924237_642762 从2D图片生成3D模型(3D-GAN) http://blog.topspe ...

  3. 【BZOJ】1857: [Scoi2010]传送带(三分)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1857 好神奇的三分.. 第一次写三分啊sad..看了题解啊题解QAQ 首先发现无论怎么走一定是在AB ...

  4. sql语句中3表删除和3表查询

    好久没来咱们博客园了,主要近期在忙一些七七八八的杂事,包括打羽毛球比赛的准备和自己在学jqgrid的迷茫.先不扯这些没用的了,希望大家能记得小弟,小弟在此谢过大家了. 回归正题:(以下的sql是本人在 ...

  5. php中数组中&的问题

    1.代码: <?php $arr = array('one','two','three'); foreach ($arr as $value){ echo 'Value:'.$value.'&l ...

  6. VisualSVN 5.1.5 破解版 手动破解教程 生成dll文件

    VisualSVN 5.1.5 破解版 手动破解教程 生成VisualSVN.Core.L.dll文件 附上本人用到的命令: ildasm "D:\Program Files (x86)\V ...

  7. Error in registration. Error: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授

     本文转载至 http://blog.csdn.net/woaifen3344/article/details/41311023 Code3000极光推送erroryour certificate n ...

  8. hdu 4055(经典问题)

    总是不能正确的将一个大问题变成子问题,而且又找不到状态转移方程. 直接导致这题想了5个小时最后还是无果... 谨记! Number String Time Limit: 10000/5000 MS ( ...

  9. git base 简单命令行

    记录几个简单的命令 1:克隆-把线上的文件复制到本地 git clone 线上地址 2:检查状态 git status 3:放入待仓储 git add.文件名 git add * (全部文件,简单粗暴 ...

  10. vue学习之旅:入门

    首先利用脚手架vue cli搭建vue环境 引入 vue <script src="https://unpkg.com/vue/dist/vue.js"></sc ...