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


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:

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”)){

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++)
            if (contexts[i].Contains("WEBVIEW"))
                webviewContext = contexts[i];

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


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