java appium webview切换处理

        Set<String> contexts = driver.getContextHandles();
        for(String item :contexts){
           // NATIVE_APP
            //WEBVIEW_com.xxx.xxxx
            System.out.println(item);
        }
        Set<String> contextNames = driver.getContextHandles();
        List<String> webViewContextNames =  contextNames
                .stream()
                .filter(contextName -> contextName.contains("WEBVIEW_"))
                .collect(Collectors.toList());
        String currentContextView = "";

        if (webViewContextNames.size() > 0){
            currentContextView = (String) webViewContextNames
                    .toArray()[webViewContextNames.size()-1];
            driver.context(currentContextView);
        }
driver.context(currentContextView); 
执行的是切换到最后一个webview
posted @ 2018-07-12 17:00  testway  阅读(767)  评论(0编辑  收藏  举报