1

New to UI automation, using Appium WinAppDriver on a UWP app, i am trying to find a way to get a list of all the elements in a particular ListView control, and then get values form each. I am maybe wrong, but there appears to be a child/parent relationship between some WindowElement, which can be seen when examining an particular screen in inspect tool. Please consider below simplified piece of code:

WindowElement x = session.FindElementsByClassName("ListView").ToList()[1];
List<WindowElement> y = x.FindElementsByClassName("ListViewItem").ToList();
foreach(WindowElement z in y)
{
     string name = z.FindElementByName("itemName").Text;
     string id = z.FindElementByName("itemID").Text;
}
  1. Is this a correct approach in general, or am i missing something fundamental about this? I want to get a list of all of the items from a ListView
  2. This statement: List<WindowElement> y = x.FindElementsByClassName("ListViewItem").ToList(); gives me an error because FindElementsByClassName() apparently returns a list of AppiumWebElement and not WindowElement
concentriq
  • 359
  • 2
  • 6
  • 16
  • AFAIK this is how the WinAppDriver works, only you do not need to call `ToList()` since FindElementsByClassName("ListViewItem") should give you an iterable. – wp78de May 24 '19 at 19:12

2 Answers2

0

Instead of

List<WindowElement> y = x.FindElementsByClassName("ListViewItem").ToList();

Try this and see if it works

var y = x.FindElementsByClassName("ListViewItem");
foreach (var z in y)
{
 string name = z.FindElementByName("itemName").Text;
 string id = z.FindElementByName("itemID").Text;
}

For my test cases, FindElements only works on the driver and not on the Element. and it always returns Ilist

Avinash
  • 188
  • 5
0

Question is asked a long time ago, but anyway:

  1. It is possible approach, but you better avoid finding elements by ClassName, especially by concrete index [1], if you classes are not unique and in future there could be added more same controls results will became wrong. Better to use unique AutomationId-s for elements if it is possible, and find elements ById, ByAccessibilityId, ByName and so on.
  2. Yes. When you are trying to get elements from WindowElement you will get AppiumWebElement. You can use it. Otherwise if you wand to get Windows element - you shoud search elements in session, as in your code beginning.
MiddleD.
  • 315
  • 1
  • 4
  • 21