How to get the webview content using appium in Java?

My application is having partial Webview and Partial Native App view. So how could I switch from Native_App to Webview?
Every time I use below code it always returns me a NATIVE_APP as context.
Set contextNames = driver.getContextHandles();
for(String contextname : contextNames){
Parent view is NATIVE_APP view and inside it I have Webview. So how could I switch to Webview and get its content in String? It is fully a native app. content-desc = Webview.

Thanks in advance!

I haven’t had the chance to verify that this works yet, but based on what others have said, you need to set WebView debugging to true in the application you are testing. I haven’t done this yet, and when I try to use code like yours, I get only one context back, NATIVE_APP.

Does anyone found solution to this issue?
I’m facing similar issue when trying to add Gmail/Hotmail account from any of the famous mail client. If you click on add account it will navigate user to Webview(where I’m not able to identify UI, Password and SignIn button elements as well).

You need to have setWebContentsDebuggingEnabled(boolean enabled) for your webviews.

You can use chrome://inspect in browser to get locators for UI element within webview.

Below code snippet will help you to find if there is any webview available -

        List<WebElement> mList = android_driver
	if (mList.size() > 0) {
		bWebView = true;
	} else {
		// android_driver.context("NATIVE_APP");

Thanks RamS for your help. Btw I’m able to resolve issue without switching contexts. Uiautomator viewer provided me the respective webview id so I’m able to resolve my issue. However other area of my application does have this problem where my app is not opening my webview in any browser. Webview is invoked with the application