首页 > 解决方案 > 如何获取特定元素的所有后代?

问题描述

我是 ios 测试新手,我将快速自动化现有 ios 项目的 UI。

问题是我无法获取特定元素的所有后代,我想知道官方函数可以将所有后代返回为XCUIElementQuery.

我尝试使用XCUIApplication().tables.descendants(matching: .cell)get XCUIElementQuery,但只得到了一种类型,如何同时获取特定元素下的不同类型?

Table, 0x282a00c30, {{0.0, 88.0}, {375.0, 641.0}}
    Other, 0x282a184e0, {{0.0, 88.0}, {375.0, 44.0}}, identifier: 'XXX'
        StaticText, 0x282a185b0, {{0.0, 88.0}, {375.0, 44.0}}, label: 'XXX'
    Cell, 0x282a18680, {{0.0, 132.0}, {375.0, 78.0}}, identifier: 'XXX', label: 'XXX', value: 0.00
        StaticText, 0x282a18750, {{127.0, 167.7}, {62.0, 13.3}}, label: 'XXX', value: 5
        StaticText, 0x282a18340, {{127.0, 151.3}, {27.0, 14.3}}, label: 'XXX'
        Button, 0x282a18820, {{127.0, 183.0}, {50.0, 8.0}}
        Image, 0x282a188f0, {{352.0, 165.0}, {8.0, 12.0}}, identifier: 'XX'
    Cell, 0x282a189c0, {{0.0, 210.0}, {375.0, 78.0}}, identifier: 'XXX', label: 'XXX', value: 0.00
        StaticText, 0x282a18a90, {{127.0, 237.0}, {137.7, 14.3}}, label: 'XXX'
        Button, 0x282a18b60, {{127.0, 253.3}, {50.0, 8.0}}
        Image, 0x282a18d00, {{352.0, 243.0}, {8.0, 12.0}}, identifier: 'XXX'
    Cell, 0x282a18dd0, {{0.0, 288.0}, {375.0, 78.0}}, identifier: 'XXX', label: 'XXX', value: 0.00
        StaticText, 0x282a18ea0, {{127.0, 315.0}, {137.7, 14.3}}, label: 'XXX'
        Button, 0x282a18f70, {{127.0, 331.3}, {50.0, 8.0}}
        Image, 0x282a19040, {{352.0, 321.0}, {8.0, 12.0}}, identifier: 'XXX'

标签: iosswiftui-automationxcode-ui-testing

解决方案


推荐阅读