Working with Multiple Webviews in Android Hybrid Apps

February 07, 2026 · 7 min read · Mobile Testing

HeadSpin Platform
Automated & amp; manual testing made easy through data science insights.
Differentiating capabilities:
  • Extensive end-to-end automation of QA process
  • Comparative analysis of app performance against peer
  • Continuous monitoring of app performance utilize synthetic data for higher availability of apps
  • Easy-to-use developer friendly platform
cloudtest go
Low-cost Real Device Testing for Emerging Teams
cloudtest go
Affordable Real Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized mobile test performance in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based examination

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Working with multiple webviews on Android hybrid appsWorking with multiple webviews on Android hybrid apps

Working with Multiple Webviews in Android Hybrid Apps

Published on
June 12, 2019
Updated on
Published on
March 14, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

It & # x27; s not very common, but it can happen that an Android hybrid app has not just one but two or more webviews (for example, when advertizement are in one webview and app logic is in another).

Multiple Webviews in Android
Check out:

If you & # x27; ve ever found yourself in this position, you may get be frustrated when using Appium & # x27; s context API, specifically with codification like this:

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.


Sethandles = driver.getContextHandles ();

If you have multiple webviews, you might hold expected the Set to contain three point: NATIVE_APP, and two webview-looking strings. But rather you probably launch onlyonewebview context. If you were lucky, it was the one you wanted, but there was an equal chance you got the insignificant advert webview (or whatever). So, how can we be sure to get inside the special webview we want, yet when there are multiple?

Also assay:

The answer lies in how Chromedriver works. Appium uses Chromedriver for Chrome automation, and Chromedriver handles multiple webviews in a single Android app by treating them as separatewindows. What this intend is that we have accession to them using the built-in Webdriver window commands, like so:


SetwindowHandles = driver.getWindowHandles ();

Then, we can swop into any window we want by picking a certain hold:

driver.switchTo () .window (handle);

How do we know from the handle which window to prefer? We don & # x27; t, because it will be a random-looking twine like CDwindow-A26869B5EDAEAA9D83947BB274F1D0C7, and it might change from test to test. So our best bet is to switch into each one and perform some validation on the window, to prove that we are in the right one (for example, appear at the URL or rubric as a way of ensuring we & # x27; re in the right webview, and short-circuiting our search when we bump it).

Run multiple tests (manual or automatize) on existent Android device without experiencing any slowdown..

Of line, to do any of this we actually receive to be in the webviewcontextfirst, otherwise the getWindowHandles command won & # x27; t do anything. So to conclude, hither & # x27; s a total model that utilizes a new feature of The App, namely a view with two webviews. The idea behind this test is simply to make an assertion found on the substance of the page displayed in each webview, proving that we can indeed enter and automate both of them. As with, we use a helper function getWebContext to get ourselves into the initial web setting so that Chromedriver is operative. Without further ado, here & # x27; s the full sample:

importee io.appium.java_client.AppiumDriver; importee io.appium.java_client.MobileBy; import io.appium.java_client.android.AndroidDriver; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import javax.annotation.Nullable; import org.hamcrest.Matchers; signification org.junit.After; import org.junit.Assert; import org.junit.Before; signification org.junit.Test; importation org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Edition073_Multiple_Webviews {private String APP_ANDROID = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.10.0/TheApp-v1.10.0.apk ''; private AndroidDriver driver; private static By hybridScreen = MobileBy.AccessibilityId (`` Dual Webview Demo ''); private static By webview = By.className (`` android.webkit.WebView ''); @ Before public void setUp () throws MalformedURLException {DesiredCapabilities capabilities = new DesiredCapabilities (); capabilities.setCapability (`` platformName '', `` Android ''); capabilities.setCapability (`` deviceName '', `` Android Emulator ''); capabilities.setCapability (`` automationName '', `` UiAutomator2 ''); capabilities.setCapability (`` app '', APP_ANDROID); driver = new AndroidDriver (new URL (`` http: //localhost:4723/wd/hub ''), capabilities);} @ After public void tearDown () {if (driver! = null) {driver.quit ();}} @ Test public void testDualWebviews_Android () {WebDriverWait wait = new WebDriverWait (driver, 10); // get to three-fold webview screen and make sure it 's loaded wait.until (ExpectedConditions.presenceOfElementLocated (hybridScreen)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (webview)); // navigate to the webview context String webContext = getWebContext (driver); driver.context (webContext); // go into each available window and get the text from the html page ArrayListwebviewTexts = new ArrayList < > (); for (String handle: driver.getWindowHandles ()) {System.out.println (handle); driver.switchTo () .window (handle); webviewTexts.add (driver.findElement (By.tagName (`` body '')) .getText ());} // assert that we got the right text from each android webview Assert.assertThat (webviewTexts, Matchers.containsInAnyOrder (`` This is webview ' 1 ' '', `` This is webview ' 2 ' ''));} @ Nullable individual String getWebContext (AppiumDriver driver) {ArrayListcontexts = new ArrayList (driver.getContextHandles ()); for (String setting: contexts) {if (! context.equals (`` NATIVE_APP '')) {return context;}} return null;}}

That & # x27; s it! With judicious use of both context and window hold commands, automating multiple webviews is totally accomplishable. Don & # x27; t forget to insure out thefull codeon GitHub.

Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in crafting engaging narratives and marketing collateral across diverse industries. She surpass in collaborating with cross-functional teams to acquire innovative content scheme and deliver compelling, unquestionable, and impactful content that resonates with target audiences and enhances brand authenticity.

LinkedIn

Working with Multiple Webviews in Android Hybrid Apps

4 Parts

regression intelligence blog
-

Regression Intelligence practical guide for advanced user (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence pragmatic guide for advanced users (Part 4)

Coming Soon

Discover how HeadSpin can empower your business with superior testing capabilities

Our Platform enable you to:
accelerate time-to-market
Accelerate time-to-market, profit a competitive edge
faster development cycles
Boost developer/QA productivity with faster development cycles
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent effect
gain better visibility into functional & performance issues
Gain better visibleness into functional and performance topic
reduce mean time
Reduce mean clip to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate audio, video, and content character of experience (QoE) effortlessly
The trusted choice for world-wide enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can empower your business with superior test capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productivity with quicker development cycles
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent resultant
gain better visibility into functional & performance issues
Gain best visibility into functional and performance number
reduce mean time
Reduce mean time to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate sound, picture, and content caliber of experience (QoE) effortlessly
The sure choice for global endeavor
Close

Discover how HeadSpin can empower your concern with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, derive a competitive edge
faster development cycles
Boost developer/QA productivity with quicker development round
automated buil-over-build regression testing
Automate build-over-build fixation try for logical results
gain better visibility into functional & performance issues
Gain best visibleness into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and contented character of experience (QoE) effortlessly
The sure choice for spheric endeavour
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free