FindElement doesn't find anything with Appium

166 views Asked by At

Using the following test method (simplified here for the purpose of the question, please ignore the design issues as this isn't the actual code)

[TestClass]
public class LoginTests
{
    protected static WindowsDriver<WindowsElement> session;

    [TestMethod]
    public void Login_WithValidCredentials_Logsin()
    {
        if (session == null)
        {
            var options = new AppiumOptions();
            options.AddAdditionalCapability("app", @"D:\myApp.exe");
            options.AddAdditionalCapability("deviceName", "WindowsPC");
            session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), options);
            Assert.IsNotNull(session);

            session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
        }

        //Arrange
        string username = "username";
        var txtUsername = session.FindElementByName("txtUsername");

        //Act
        //To be developed

        //Assert
        Assert.AreEqual(username, txtUsername.Text);
    }
}

I can't find any element in the UI, the app launches correctly when the test is ran (having WinAppDriver running in the background) but no matter how I try to find the elements on the screen I always get the same error message

"error":"no such element"

"message":"An element could not be located on the page using the given search parameters."

Update 1

Based on the first comment below, I used inspect.exe to confirm the name of the element on the screen that I'm trying to get and nop, I can't find it in the test. enter image description here

enter image description here

0

There are 0 answers