Unable to detect selector element in a ionic5 application using appium & c#

Viewed 163
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Remote;
using System;
using System.Threading;
using Xunit;


namespace XUnitTestProject2
{
    public class UnitTest1
    {
        [Fact]
        public void Test1()
        {
            Thread.Sleep(3000);
            var driver = InitiliseDriver();
            
            //Login Page
            driver.FindElement(By.Id("username")).SendKeys("TestUser");
            driver.FindElement(MobileBy.Id("password")).SendKeys("newpassword");
            driver.FindElement(MobileBy.Id("91268f5d-d21e-4ef5-9886-c1d19f2799a7")).Click();
        }
        private RemoteWebDriver InitiliseDriver()
        {
            //Set the capabilities
            DesiredCapabilities cap = new DesiredCapabilities();
            cap.SetCapability("platformName", "Android");
            cap.SetCapability("platformVersion", "9.0");
            cap.SetCapability("app", "C:\\Users\\jamesa\\Downloads\\app-debug.apk");
            //cap.SetCapability("automationName", "uiautomator2");
            return new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), cap);          
        }
    }
}

  • My nuget packages are Appium.WebDriver(4.1.1); Microsoft.Net.Test.Sdk(16.0.1); Selenium.Support(3.141.0); Selenium.WebDriver(3.141.0); Xunit(2.4.0); Xunit.runner.visualstudios(2.4.0); MSTest.TestAdapter(2.1.2); MSTest.TestFramework(2.1.2)

  • My Desired Capabilities are platformName- Text- Android; platformVersion- Text - 9.0; app - Text - \\\

This is the session details I am getting I do have selector ID but the server is not picking it

Note: - I am able to launch the application successfully but the server is unable to pick the element. - The application is built in an Ionic way (Ionic 5)

1 Answers

You need to set your driver context to WEBVIEW, ionic builds apps with webview (not native), also you might want to build your app in debug mode. Here is more details on testing hybrid applications with appium.

In your case you would need to add something like this, before executing the tests

driver.context("WEBVIEW");
Related