appium如何切换Native和WebView

方法一:

Set<String>contexts=driver.getContextHandles();
driver.context((String)contexts.toArray()[1]);  //选取webview开头的context

方法二(官方示例):

driver.getContextHandles().forEach((handle) -> {
                if (handle.contains("WEBVIEW")) {
                    driver.context(handle);
                }
            });

此外,好多chromdriver不兼容,我再上传一个chromdriver--云盘链接如下:

https://pan.baidu.com/s/1dFRTgRZ

 方法三:

public void context_to_webview(AppiumDriver<MobileElement> mdriver) {
        Set<String> ContextHandles = mdriver.getContextHandles();
        LOGGER.info("All ContextHandles :" + ContextHandles);
        if (ContextHandles.size() == 1) {
            LOGGER.info("该web页未开启debug状态");
        } else {
            mdriver.getContextHandles().forEach((handle) -> {
                if (handle.contains("WEBVIEW")) {
                    mdriver.context(handle);
                }
            });

        }
    }

原文链接:https://testerhome.com/topics/10951

原文地址:https://www.cnblogs.com/liuwanqiu/p/8251615.html