Skip to main content
🚀 Self Healing AI Agent now live in App Automate! Auto-fix flaky tests instantly with zero code changes. Enable now!
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin our Discord

Debug app WebView automation issues

Learn about possible solutions to resolve app WebView automation issues on BrowserStack App Automate.

Learn about possible solutions if you face issues using Android app WebView automation on BrowserStack App Automate.

Issues

When you run tests on BrowserStack App Automate, you may encounter the following app WebView automation issues while using Android devices on BrowserStack:

  • App is unable to retrieve the WebView context
  • After switching to the WebView context, your app is unable to interact with the loaded elements
  • WebView pages of the app fail to load

Causes

Some of the common reasons for this issue are:

  • App WebView automation is tested locally using simulators and not real devices
  • Appium version or protocol mismatch between your local setup and BrowserStack
  • setWebContentsDebuggingEnabled property is not enabled for WebViews in your app
  • Test script is not optimized to work with the ChromeDriver 89 or higher supported by BrowserStack
  • WebView timeout set is less than the time it takes to get WebView context

Resolutions

  • Ensure that your WebView automation runs on the app locally using real mobile devices. BrowserStack App Automate only provides real mobile devices; thus your testing experience with real mobile devices locally can be comparable with BrowserStack.
  • Ensure that your local Appium sessions and BrowserStack Appium sessions are running on the same Appium protocol(W3C or MJSONWP) and Appium version. Check out BrowserStack - Capabilities for running mobile app tests to learn about the specific Appium protocol & Appium version on BrowserStack App Automate.
  • Ensure that the setWebContentsDebuggingEnabled property is enabled for WebViews in your app. This property enables debugging of web contents loaded in the WebView of your app. Check out WebView documentation for more information.
  • If you are testing a hybrid app built using frameworks such as Ionic, Cordova, etc., you can launch your app in the WebView context by setting the autoWebView capability to true in your Appium sessions. Check out the following resources to learn more about this capability:
  • BrowserStack Android devices support ChromeDriver 89 or higher. From ChromeDriver 89 onwards, your Appium scripts need to find the correct WebView window to interact with WebView elements and switch to it using the driver.switchTo().window(handle) command. Check out handling multiple WebViews to learn more about multiple WebViews.
  • Occasionally the time taken for the WebView context to be active might be longer, causing your tests to fail. See handle timeouts for more ways to manage this. You can increase this timeout using autoWebViewTimeout Appium capability. Check out Desired Capabilities - Appium to learn more about this capability.

Additional WebView best practices

Enable WebView debugging without rebuilding your app

If you can’t rebuild your app to set setWebContentsDebuggingEnabled, use the enableWebviewDebug capability instead. BrowserStack patches the app at install time so WebView can be automated without a debug build:

Patch WebView debugging at install time
Copy icon Copy

This capability is Android only; it fails with BROWSERSTACK_INCOMPATIBLE_OS on iOS. It isn’t supported for .apks files, where it fails with BROWSERSTACK_UNSUPPORTED_CAPABILITY_WITH_APKS. It also can’t be combined with resignApp: false.

Wait for the WebView context before switching, and switch back when you’re done

The WEBVIEW context isn’t available the instant the WebView renders. Poll for it with an explicit wait, and switch back to NATIVE_APP once you finish interacting with WebView elements:

Wait for and switch WebView context
Copy icon Copy

Pin the ChromeDriver version to your app’s embedded Chromium build

If your app embeds a specific version of Chromium, pin the ChromeDriver version so it matches. Check your app’s Chromium version with adb shell dumpsys package com.android.webview | grep versionName:

Pin the ChromeDriver version
Copy icon Copy

Views rendered outside the accessibility tree

Some native views, such as Google Maps or Metal and OpenGL layers, are rendered outside the accessibility tree and won’t appear in Appium’s page source even when they’re visible on screen. Use coordinate-based taps for these views only as a last resort.

Need some help?

If you need additional help, contact our Support team.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle