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

猜你喜欢

转载自www.cnblogs.com/testway/p/9300426.html