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

    }

  • 相关阅读:
    make、make clean、make install、make uninstall、make dist、make distcheck和make distclean
    Eclipse开发C/C++ 安装配置
    没有文件扩展“.js”的脚本引擎问题解决
    Linux目录架构详解
    Linux查看硬件信息以及驱动设备的命令
    23种设计模式彩图
    ACE在Linux下编译安装
    void及void指针含义的深刻解析
    centos7.x设置nginx开机自启动
    Centos7防火墙关闭和启用iptables操作
  • 原文地址:https://www.cnblogs.com/111testing/p/7502951.html
Copyright © 2011-2022 走看看