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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM