9

In KitKat we were able to get webview view hierarchy from a UIAutomator dump if focus was placed on the webview. I was wondering if there was substitute functionality for getting webview view hierarchy with the lollipop release, or if that functionality was lost in the release?

3 Answers 3

3

Took me a while to work this out, but basically, for practical purposes, yes this functionality was lost in this release.

There are some kludgy work-arounds but they aren’t reliable.

Your best bet is to write an actual unit test that is run by uiautomator, and use the dumpWindowHierarchy API to extract it yourself. If you are doing this it is important to ensure the WebView you wish to extract is created after uiautomator has started (but obviously before you make the call to dumpWindowHierarchy). The best way to achieve that will be depend on your exact circumstances.

I wrote up more speculation on why this may have changed in Lollipop in a blog post.

1

I'm not sure about what you need to do, but maybe setWebContentsDebuggingEnabled() could help. Enabling this will allow you to debug the content of your WebView using Chrome, it may also affect the behavior of the UiAutomator so give it a chance!

WebView web = ...
web.setWebContentsDebuggingEnabled(true);

A more detailed docs about remote debugging on webviews can be found here.

1
  • Thanks for taking a look! I am familiar with setWebContentsDebuggingEnabled, and Chrome Debugging Webviews. Unfortunately this is for 3rd party applications that I can't repackage.
    – shibbybird
    Jan 2, 2015 at 14:38
1

This appears to have been fixed in Android System Webview v44 upwards for Android Lollipop. Just had a go this morning and dump now appears to give me the view hierarchy. Try upgrading webview and having another go :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.