How do I target a combo box out of many combo boxes on screen using Appium

291 views Asked by At

Given:
Windows 10 Pro Latest
Windows App Driver Latest
Appium extension for Visual Studio 2019 Latest
WPF Application


I have a simple WPF application that just has a combo box on it and I'm just trying to perform a simple test on it. If I use FindElementByClassName method, it works. However, what if there are more than one combo box on the screen? I thought I could use .FindElementByName or .FindElementByAccessibilityId, but these do not work. (Regarding the latter) It does find the combo box element and clicks it but the items appear for a moment and then disappears.

var comboNumber5 = session.FindElementByClassName(nameof(ComboBox));  //This works

vs

var comboNumber5 = session.FindElementByAccessibilityId("combo5"); //Does not work  

Code:

[TestMethod]
public void Combo5Test()
{
    var comboNumber5 = session.FindElementByClassName(nameof(ComboBox));

    comboNumber5.Click();

    var comboNumber5Items = comboNumber5.FindElementsByClassName(nameof(ListBoxItem));

    Assert.IsTrue(comboNumber5Items.Any());
    var lastItem = comboNumber5Items.Last();
    lastItem.Click();

    Assert.AreEqual(comboNumber5.Text, lastItem.Text);

}


Credit: https://github.com/mglodack/WPF-UI-Test-Automation

1

There are 1 answers

1
Rod On

Turns out in my xaml file I wasn't using the x:Name binding. I was just using the Name property.