zoukankan      html  css  js  c++  java
  • 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(); //关闭当前窗口
          }

    }

  • 相关阅读:
    js中给一个元素添加事件
    asp.net客户端回调
    (转)web元素之input (javascript)功能
    在wcf中使用基于证书的授权和保护
    (转)IE与FireFox的js和css几处不同点
    IE&FF兼容性问题
    solaris UFS文件系统 要点
    perl命令行 代替 各种shell 一则
    nginx中的验证模块
    漂亮的正则,素数查找
  • 原文地址:https://www.cnblogs.com/111testing/p/7502951.html
Copyright © 2011-2022 走看看