Writing simple code using Appium with C#

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.

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.

Karthik KK


  1. Sathu says:

    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. Vishal says:

    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. Kavitha says:

    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, Dictionary2 parameters)
    at OpenQA.Selenium.Appium.AppiumDriver
    1.Execute(String driverCommandToExecute, Dictionary2 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.AndroidDriver1..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. Jumana says:

    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”, ” com.abc.def.ghi”);
    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”]

Leave a Reply

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