Set context with c# and Ionic


I read the documentation but no have information about do with C# ( )

I have this CODE:

using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Remote;
using System.Drawing.Imaging;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace NEWTEST
    public class Test13
        AndroidDriver<AndroidElement> driver;
        DesiredCapabilities cap;

        public void Initdriver()

            cap = new DesiredCapabilities();
            cap.SetCapability("platformName", "Android");
            cap.SetCapability("deviceName", "Mi A1");
            cap.SetCapability("appPackage", "app.test.customerapp");
            cap.SetCapability("appActivity", "app.test.customerapp.MainActivity");
            cap.SetCapability("automationName", "Uiautomator2");
            cap.SetCapability("autoWebview", true);
            cap.SetCapability("setWebContentsDebuggingEnabled", true);
            driver = new AndroidDriver<AndroidElement>(new Uri(""), cap);
            driver.Context = ("WEBVIEW_app.test.customerapp");


        public void Test4565()


            //Take the screenshot
            Screenshot image = ((ITakesScreenshot)driver).GetScreenshot();
            //Save the screenshot
            image.SaveAsFile("C:/temp/Screenshot.png", ScreenshotImageFormat.Png);




        public void CloseDriver()

And in the appium server says that I have 2 contexts, but I do not know how to establish the context with the web view.:

Getting a list of available webviews
[ADB] Running 'C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe -P 5037 -s ce091719ddb87f2c02 shell cat /proc/net/unix'
[AndroidDriver] WEBVIEW_25848 mapped to pid 25848
[AndroidDriver] Getting process name for webview
[ADB] Running 'C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe -P 5037 -s ce091719ddb87f2c02 shell ps'
[AndroidDriver] Parsed pid: '25848' pkg: 'app.test.customerapp' from
[AndroidDriver]     USER      PID   PPID  VSIZE  RSS   WCHAN              PC  NAME
[AndroidDriver]     u0_a509   25848 3269  110120 381736 SyS_epoll_ 0000000000 S com.riafinancial.customerapp
[AndroidDriver] Returning process name: 'app.test.customerapp'
[AndroidDriver] Found webviews: ["WEBVIEW_app.test.customerapp"]
[AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_app.test.customerapp"]

How i can select the context with the webview “WEBVIEW_app.test.customerapp”???

Thank you very much in advance

It looks like you have it almost right in your code above. I use Appium with Java so mine might look a little different but where you have

driver.Context = ("WEBVIEW_app.test.customerapp");

I have:

((AppiumDriver<MobileElement>) driver).context(contextName);

It could be different in C# but notice that in my code, driver.context() is a method that accepts the context you want as a parameter where as you are trying to set driver.Context like it is a property


and see if that works for you. If not, could you attach some error logs and we can investigate further.

Good Luck!