Site Loader
Auckland, New Zealand
In this post we will start to write a very simple code using Appium with C# to automate android mobile application. Since this post is more like the posts we discussed in Appium with Java in our ExecuteAutomation blog and video series, I am not going to write much on the explanation of nitty-gritty details in this post. Here is the complete video of the discussion Here is the complete code from the above video discussion.
    public class UnitTest1

        //Creating instance for Appium driver
        AppiumDriver driver;

        public void TestMethod1()

            DesiredCapabilities cap = new DesiredCapabilities();
            cap.SetCapability("deviceName", "donatello");
            cap.SetCapability("appActivity", "com.example.calculator");

            //Launch the Android driver
            driver = new AndroidDriver(new Uri(""), cap);

Thanks for reading the post and watching the video !!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

17 Replies to “Writing simple code using Appium with C#”

  1. Hi Karthik,

    Thanks for all the info about Appium on your site. Can you please send me sample code about how to launch a mobile web page in chrome. Am using samsung galaxy tablet and want to test our website in the chrome browser built in it. It would be of great help if you do this. Thanks a ton

  2. Hi Karthik,

    I am looking to swipe an element in C# to unhide another element. Can you please suggest how can i do that?

  3. Hi Karthik ,I tried the same code but I get a SocketException.

    The complete message is given : Any suggestions ? TIA.

    Test Name: TestMethod1
    Test FullName: Training_Appium.UnitTest1.TestMethod1
    Test Source: D:\Work\Training\Training_Appium\Training_Appium\UnitTest1.cs : line 16
    Test Outcome: Failed
    Test Duration: 0:00:02.484985

    Result StackTrace:
    at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
    at OpenQA.Selenium.Appium.AppiumDriver`1.Execute(String driverCommandToExecute, Dictionary`2 parameters)
    at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
    at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
    at OpenQA.Selenium.Appium.AppiumDriver`1..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
    at OpenQA.Selenium.Appium.Android.AndroidDriver`1..ctor(Uri remoteAddress, DesiredCapabilities desiredCapabilities)
    at Training_Appium.UnitTest1.TestMethod1() in D:\Work\Training\Training_Appium\Training_Appium\UnitTest1.cs:line 23
    Result Message:
    Test method Training_Appium.UnitTest1.TestMethod1 threw exception:
    OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server —> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
    — End of inner exception stack trace —
    at OpenQA.Selenium.Appium.Service.AppiumCommandExecutor.Execute(Command commandToExecute)
    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)

  4. Hi i tried setting up appium with Selenium in xamarin studio- but i got the following error – could u please tell me where did i go wrong?.Can u please be more specific what did i miss?

    String strHost = “”;
    String strPort = “4723”;

    DesiredCapabilities cap = new DesiredCapabilities();
    Uri urlObj = new Uri(“http://”+strHost+”:”+strPort+”/wd/hub”);
    cap.SetCapability(“browserName”, “Android”);
    cap.SetCapability(“platformName”, “Android”);
    cap.SetCapability(“platformVersion”, “4.4.2”);
    cap.SetCapability(“deviceName”, “emulator-5556”);
    cap.SetCapability(“appPackage”, ””);
    cap.SetCapability(“app”, “abc.apk”);
    driver = new RemoteWebDriver(urlObj,cap);

    OpenQA.Selenium.WebDriverException : Unexpected error. Parameters were incorrect. We wanted {“required”:[“desiredCapabilities”],”optional”:[“requiredCapabilities”,”sessionId”,”id”,”sessionId”,”id”,”sessionId”,”id”,”sessionId”,”id”,”sessionId”,”id”,”sessionId”,”id”]} and you sent [“desiredCapabilities”,”capabilities”]

  5. Hi Karthik,

    I am trying to open notepad using Appium with C# but getting error (Additional information: Unexpected error. The URL ‘/session’ did not map to a valid resource). Please help me out to fix this. Let me know what is wrong in below code:

    using OpenQA.Selenium.Appium.Windows;
    using OpenQA.Selenium.Remote;
    using System;

    namespace AppiumPOC
    class Program
    private static readonly string driverUrl = “”;
    //private static readonly string driverUrl = “”;
    //private static readonly string app = “Microsoft.WindowsAlarms_8wekyb3d8bbwe!App”;
    private static readonly string app = @”C:\Windows\System32\notepad.exe”;

    static void Main(string[] args)
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.SetCapability(“platformName”, “Windows”);
    capabilities.SetCapability(“deviceName”, “WindowsPC”);
    capabilities.SetCapability(“app”, app);

    var x = new WindowsDriver(new Uri(driverUrl), capabilities);

  6. Hello,

    I did the same like video, but i got this error:
    “The ‘Dispose’ method of type ‘OpenQA.Selenium.Appium.Service.AppiumCommandExecutor’ in the ‘appium-dotnet-driver, Version =, Culture = neutral, PublicKeyToken = null’ integrated code does not have an application.”
    I changed appium versions but the error didn’t changed (Only Version number changed on error). Please provide us both versions (appium and selandroid and etc)
    Thank you

  7. Hi,

    At 5:20 in your video, how do you know that the device name = “devicename” and the value is “donatello”? Is there a way to find that out from the application you are testing?

    Many Thanks

  8. Hi,

    At 5:20 in your video, you enter the device capabilities. How do you know that the values are “devicename” and “donatello”. Is there a way of checking these values for the application I want to test?

    Many Thanks

    1. I used ADB command to get the devices attached in my machine
      Use this command
      adb devices -l
      Karthik KK

  9. Hi Karthik,

    I have learnt a lot from your videos. very well explained.
    I am currently automating BDD driven mobile app automation using Appium, specflow, c#
    Currently stuck on how to execute tests in an order.
    I have tried setting scenario names starting with 001, 002 etc to maintain order, but still somehow is not working as required order.

    Any tips?


    1. There is no way we can run in order, but again try making each and every scenario as independent, which will make your test to run in any order !

      Karthik KK

  10. Stuck with
    System.TypeLoadException: ‘Method ‘Dispose’ in type ‘OpenQA.Selenium.Appium.Service.AppiumCommandExecutor’ from assembly ‘appium-dotnet-driver, Version=, Culture=neutral, PublicKeyToken=null’ does not have an implementation.’
    i have tried all version of appium web driver but no use. anyone has got the same and resolved, please let me know.

    1. Same with me. I have updated all the references, then downgraded them one version at a time – still no luck. I cannot run the CalculatorTest tests.
      Did you find anything? any luck?

Leave a Reply

Your email address will not be published. Required fields are marked *