Switching between the webviews getting error in android hybrid application

Hi all:

In my hybrid application, some screens are integrated with native and HTML5 modules. I can able to get the webview content with below code. While I’m switching into other webview screens, the Appium Driver find the elements from the previous screen. In my app, both the webviews(Screen) has some common CSS value and ClassName. And also, the webview names are common throughout all screens(webviews) in the application.

         Set<String> contextNames = driver.getContextHandles();
         for(String contextName : contextNames){
             System.out.println(contextName);
             if(contextName.contains("WEBVIEW"))
             {
                      driver.context(contextName);
             }
         }

I’m using:
Appium v1.3.1
Android real device -v4.4.2
Java Client - v1.6.1

How to kill/close the previous webview??? or Is there any work-around for this??

You have to supply the explicit name of the WEBVIEW in order to be sure that the elements you refer to exists.

@Hassan_Radi: All webview names are common in my application. I have tried(Set) the different names for getContextHandles() to get the new webviews like below: But it didn’t work out.

      Set<String> contextNames1 = driver.getContextHandles();
         for(String contextName1 : contextNames1){
             System.out.println(contextName1);
             if(contextName1.contains("WEBVIEW"))
             {
                driver.context(contextName1);
                }
           }

See this for help.