码迷,mamicode.com
首页 > 移动开发 > 详细

appium之Context切换

时间:2017-09-11 00:53:07      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:查看   detail   details   close   web   url   text   csdn   this   

原文地址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切换

标签:查看   detail   details   close   web   url   text   csdn   this   

原文地址:http://www.cnblogs.com/111testing/p/7502951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!