Hybrid app returning context as NativeApp instead of Webview


iOS hybrid application has Web view, but returning the context as Native app. How to switch the context to web view.
Here is the code snippet i am using:

Set contextNames = driver.getContextHandles();
for (String contextName : contextNames)
if (contextName.contains(“WEBVIEW”))

 			System.out.println("App not switched to webview");

Please let me know how to switch to Webview


See this thread may help you:

I have Instrumented the app. Able to view the app as Web view in Reflection screen, but when i run the app. It launches as native app. Unable to change to Web view and my tests are failing.

My Code:

 DesiredCapabilities dc = new DesiredCapabilities();
  dc.setCapability(SeeTestCapabilityType.REPORT_DIRECTORY, reportDirectory);
  dc.setCapability(SeeTestCapabilityType.REPORT_FORMAT, reportFormat);
  dc.setCapability(SeeTestCapabilityType.TEST_NAME, testName);
  dc.setCapability(MobileCapabilityType.UDID, "8136dac31b54f7a65f8af3ac77b2527a33a57adb");
  dc.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.ZirconConnect.Zircon");
  dc.setCapability(SeeTestCapabilityType.INSTRUMENT_APP, true);
  //dc.setCapability ("newCommandTimeout", 120);
  driver = new SeeTestIOSDriver<>(new URL("http://"+host+":"+port), dc);

Here is the error i got

[Fri Jun 09 11:01:12 IST 2017] [driver] Starting test: ‘FirstiOSTest’
[Fri Jun 09 11:01:12 IST 2017] [driver] {dontGoHomeOnQuit=false, noReset=false, dontStopAppOnReset=false, instrumentApp=true, bundleId=com.ZirconConnect.Zircon, reservationDuration=240, reportFormat=xml, fullReset=false, waitForDeviceTimeout=120000, useRemoteGrid=false, reportDirectory=reports, [enableclientlog, enableclientlogger]=false, autoWebview=false, udid=8136dac31b54f7a65f8af3ac77b2527a33a57adb, platformName=iOS, testName=FirstiOSTest}
[Fri Jun 09 11:01:12 IST 2017] [driver] context: NATIVE_APP_INSTRUMENTED
[Fri Jun 09 11:01:12 IST 2017] [driver] application under test:
[Fri Jun 09 11:01:12 IST 2017] [driver] app path: null
[Fri Jun 09 11:01:12 IST 2017] [driver] full reset: false
[Fri Jun 09 11:01:12 IST 2017] [driver] instrument: true
[Fri Jun 09 11:01:12 IST 2017] [driver] no reset: false
[Fri Jun 09 11:01:12 IST 2017] [driver] bundleId: com.ZirconConnect.Zircon
[Fri Jun 09 11:01:12 IST 2017] [driver] launch timeout ms: null
[Fri Jun 09 11:01:12 IST 2017] [driver] browser: false
[Fri Jun 09 11:01:12 IST 2017] [driver] connecting localhost:8889
[Fri Jun 09 11:01:12 IST 2017] [driver] Call of getSessionID returned: 390c
[Fri Jun 09 11:01:12 IST 2017] [driver] setting reporter directory: reports
[Fri Jun 09 11:01:12 IST 2017] [driver] setting reporter format: xml
[Fri Jun 09 11:01:12 IST 2017] [driver] setting test name: FirstiOSTest
[Fri Jun 09 11:01:12 IST 2017] [driver] wait for device ‘@serialnumber=‘8136dac31b54f7a65f8af3ac77b2527a33a57adb’’ timeout-ms=‘120000’
[Fri Jun 09 11:01:20 IST 2017] [driver] Device ‘ios_app:iPhone’ ready
[Fri Jun 09 11:01:21 IST 2017] [driver] launching com.ZirconConnect.Zircon …
[Fri Jun 09 11:01:25 IST 2017] [driver] Call of launchApp returned: native
[Fri Jun 09 11:01:26 IST 2017] [390c] [driver] [start] context(“WEBVIEW”)
[Fri Jun 09 11:01:26 IST 2017] [390c] [driver] [end] context
io.appium.java_client.NoSuchContextException: No such context found: WEBVIEW
Build info: version: ‘2.53.1’, revision: ‘a36b8b1cd5757287168e54b817830adce9b0158d’, time: ‘2016-06-30 19:26:09’
System info: host: ‘ZIRCON-AMBIKA’, ip: ‘’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.8.0_71’
Driver info: driver.version: SeeTestIOSDriver
at com.experitest.appium.STState.setContext(STState.java:77)
at com.experitest.appium.SeeTestIOSDriver.context(SeeTestIOSDriver.java:429)
at samplegradle.iOSZirconTest.setUp(iOSZirconTest.java:59)


Can you please try setting context to “Webview_1” or “Web”

// OR 

let us know if this resolves the issue

BTW, in the upcoming version we will support the get context handlers command

Set<String> contexts = driver.getContextHandlers(); 

Thanks Tom, it started working after changing the context to WEBVIEW_1

Hi Tom,

I am trying to Switch from Native to Webview in iOS.

From example, There are terms and conditions link in my Native and clicking on that opens in Web browser .

After clicking on link in Native , Device gets disconnected and Set Context not working .

Could you help me on this issue.

Can someone help me on this issue.

Hi Tom,

Could you please help me on this.

Thanks in advance .

Best Regards,
Sudhakar MK

Hi Sudhakar

Which browser is opened when you click on the link?

is it safari?

are you working with or without instrumentation?

can you share with us the steps to reproduce the scenario?

Hi @Tom ,

I too face the issue wherein i am not able switch to WEBVIEW and the getcontext returns me only NATIVE_APP and not WEBVIEW.

Do i need to do any changes to the ipa file to make this working?
I am using iOS hybrid app.

code i am using:

// Switching to webview
        Set<String> contextNames = appiumDriver.getContextHandles();
        for (String contextName : contextNames) {
            System.out.println(contextName); //prints out something like [NATIVE_APP, WEBVIEW_<APP_PKG_NAME>]
                System.out.println("Switched to: "+contextName);
        return appiumDriver;

Can you share the capabilities you use to initialize a session?

Do you instrument your application?



I am facing the same problem and even this didn’t help , plz if you have any solution provide it to me, thanks

Hi @Alaa,

It would greatly help if you could share more content such as how you have set up your capabilities, perhaps a code snippet would also help to show how you are trying to switch context.

thanks for your respond this is the caps i have sat up

Dear All,

I had a same issue with WEBVIEW elements not being identified.

It was solved by instrumenting the application. If you are using Appium Studio, in the application capabilities section, there is a checkbox called “Instrument”. Selecting the Instrument checkbox before recording the script solved the problem. Selecting Instrument checkbox also added a new line of code:

dc.SetCapability(“instrumentApp”, true);

In case you are searching where is the Application Capabilities section: In Appium Studio, on the left hand side, there are 3 sections: 1) Device manager section with list of all connected devices, 2) Application Manager section with the list of all applications installed and 3) Application Capabilities section with 3 checkboxes: Install, No Reset, Instrument. This section is below the Application Manager section. Selecting the Instrument checkbox before recording the scripts solved the problem.

The code generated by Appium Studio looks like this:
//package ;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.iOS;
using NUnit;
using NUnit.Framework;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Support.UI;

namespace Experitest
public class WebviewLogin_Instrumented
private string reportDirectory = “reports”;
private string reportFormat = “xml”;
private string testName = “WebviewLogin-Instrumented”;
protected AndroidDriver driver = null;

    DesiredCapabilities dc = new DesiredCapabilities();

    public void SetupTest()
        dc.SetCapability("reportDirectory", reportDirectory);
        dc.SetCapability("reportFormat", reportFormat);
        dc.SetCapability("testName", testName);
        dc.SetCapability(MobileCapabilityType.Udid, "91FY17BQ9");
        dc.SetCapability(AndroidMobileCapabilityType.AppPackage, "com.clearhorizon.chimedev");
        dc.SetCapability(AndroidMobileCapabilityType.AppActivity, ".MainActivity");
        dc.SetCapability("instrumentApp", true);
        driver = new AndroidDriver<AndroidElement>(new Uri("http://localhost:4723/wd/hub"), dc);

    public void TestWebviewLogin_Instrumented()
        driver.Context = "WEBVIEW_1";
        driver.FindElement(By.XPath("xpath=//ion-col[@class=\"syncButton md hydrated\"]")).Click();
        new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists(By.LinkText(" Synchronise")));
        driver.FindElement(By.LinkText(" Synchronise")).Click();
        new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists(By.Id("idSIButton9")));
        new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementExists(By.Id("i0118")));
        new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementExists(By.Id("idSIButton9")));

    public void TearDown()


1 Like