1

Im working on a squish based test and try to get decent (visible) items from a QML ListView that are deeply nested that i just can't pick due to its dynamic behavior

I've get the list itself by using waitForObject with a object map name

There are several nested items in the list an i want to get all occurrences of the MyTypeCCC_QMLTYPE_72 when property visible is true

I've dumped my current class/property child-hierachy:

MyTypeAAA_QMLTYPE_195
  children[0] QQuickItem
    children[0] QQuickColumn
      children[0] MyTypeBBB_QMLTYPE_189
        children[0] MyTypeCCC_QMLTYPE_7 visible(true)

I've found this in the Squish-KB: https://kb.froglogic.com/display/KB/Example+-+Finding+child+objects+by+type+and+property+values

so i can write my own search code traversing the tree etc. but i think that could(should) be an easier solution?

  • can i rely on the exact hierarchy? (but what i the UI design changed another time)
  • i could maybe add ids to the MyTypeCCC_... if that helps
  • I've got several of this list with different types/nesting and i hope to find a easy solution that works for all/many of the case

any ideas?

Dvyn Resh
  • 980
  • 1
  • 6
  • 14
llm
  • 557
  • 3
  • 15

1 Answers1

0

ListView is a subclass of Flickable and all its delegates are immediate children of ContentItem, you can safely iterate over its children to get all list items, but be aware that not all of its children are list delegates, so you have to filter them, e.g. by type. To find nested elements just search for them inside list item, i.e. use list item as a container. To create container locator you can use its coordinates (these are coordinates within the list, so they will be unique). Code may look like this:

list_view = findObject(list_locator)
nested = []
for i in range(list_view.contentItem.children.count):
    item = list_view.contentItem.children.at(i)
    if className(item) == 'MyTypeAAA':
        netsed.append(findObject({'container': {'x': item.x, 'y': item.y, 'type': className(item)}, 'type': 'MyTypeCCC'}))
Vader
  • 3,675
  • 23
  • 40
  • and what about non ListView Items with deeply nested items - is there some sort of filter feature (XPath like or something?) or do i need to travel down the children hierarchy and find wanted content by myself? – llm Aug 19 '19 at 07:23
  • 1
    @llm there is no generic solution, but usually you don't need to traverse full tree, instead just use a topmost container where an element you are looking for is unique and search inside it. Also if you don't care about structure, but just want to get all elements with certain attributes use `findAllObjects` that returns all matching elements regardless of their position in object tree. – Vader Aug 19 '19 at 08:13