How to switch to WEBVIEW context using SafariLuancher app with C#?

Hi

I am trying to open a URL on my iPhone. I’ve managed to get Safarilauncher installed on the iPhone and I can launch Safarilauncher via the test. However, once Safari launchers i tried switching context using these code samples below but I am unable to switch context:

driver.Context = “WEBVIEW_1”;
driver.Context = “WEBVIEW”;

I’ve had a look at this documentation but I cant seem to find any C# examples:
https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/hybrid.md

I’ve also tried reading through a bunch of posts but I cant seem to find a solution that works with C#.

I am not a developer so I cant seem to get this to work. Can some one please assisst?

Thanks in advance.

Edit. I have seen a lot of post suggesting using driver.getContext(). When i try this I get the red squiggly line and the method is not recognized. Does anyone know why this occurs?

Hi @Ash,

I have done this using Java.

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

Hello @Ash,

I`m also facing the same issue, have you managed to resolve this in the mean time ?

Hey Gery,

I tried the following code below on Android and this worked:

        var contexts = ((IContextAware)driver).Contexts;
        string webviewContext = null;
        for (int i = 0; i < contexts.Count; i++)
        {
            Console.WriteLine(contexts[i]);
            if (contexts[i].Contains("WEBVIEW"))
            {
                webviewContext = contexts[i];
                break;
            }
        }

Its not working on my iOS device for some reason. Give it a try.

Ash

I have used mentioned code but it gives some error , I am using java