Cannot find WebView when searching for context in Hybrid application

Hello,

I’m currently using Appium and have hit an issue with regard to finding the WebView context. Using UIAutomator I can inspect the WebView and see its child elements, however I cannot access any of these by using CSS selector/ XPATH because I cannot switch to WebView.

I have tried looping over driver.getContextHandles(), however this simply returns “NAVTIVE_APP”.

Android version being used is 5.0.1 and the latest version of Appium.

Can anyone shed any light as to why this may be happening?

For using webview context enable WebView debugging, for this “setWebContentsDebuggingEnabled” flag should be inside the WebView class by developer.
Then using chrome remote debugger you can spy or inspect webview elements
url : https://developer.chrome.com/devtools/docs/remote-debugging9

Is this the case for being able to identify the “WEBVIEW” in get contexts too as I am not able to view this at all?

The code I use is :

Set contextNames = driver.getContextHandles();
for(String contextName : contextNames)
{
System.out.println(contextName);
}

However all that is printed out [NATIVE_APP]

You should ask app developer to set this flag “setWebContentsDebuggingEnabled” or enable webview debugging while creating app then only getContextHandles() will detect both the contexts
Also app should be build for Android 4.4+ version

Thank’s for the quick reply. I’ll do this now and will hopefully have this resolved soon.

UIAutomator inspector shouldn’t show you any WebView children elements if that’s true web/hybrid app. Go to Chrome devices remote debugging (chrome://inspect/#devices) and check if there is any WebView. If no, that means you have native app.

Hi ,
I have been experiencing the same issue, with a twist tho. The “setWebContentsDebuggingEnabled” is set to true. However, everytime I run , I’m getting different number of contexts. Yesterday I was getting only the "NATIVE_APP’ one, today morning I got “NATIVE_APP” and “WEBVIEW_chrome” and now I’m getting those two and another one “WEBVIEW_<package_name>”. Why is this happening?
I have no clue