【问题标题】:How can I locate an XCUIElement searching by partial label text in Swift?如何在 Swift 中通过部分标签文本搜索找到 XCUIElement?
【发布时间】:2018-08-09 08:00:24
【问题描述】:

我一直在使用这种方法定位 XCUIElements:

app.staticTexts["Full Label Text"]

但是如果我只知道标签文本的一部分呢?部分标签文本是动态生成的(例如“Item #1”、“Item #2”等),所以我想通过查找包含部分文本的元素来搜索它(例如通过“Item”搜索)。在 Swift 中有什么方法可以做到这一点吗?

【问题讨论】:

    标签: ios swift automation xctest xcuitest


    【解决方案1】:

    您可以找到带有谓词的元素。使用来自XCUIElementQuerycontaining(_ predicate: NSPredicate) -> XCUIElementQuery 方法。

    let predicate = NSPredicate(format: "label CONTAINS[c] 'Item'")
    let labels = XCUIApplication().staticTexts.containing(predicate)
    

    【讨论】:

    猜你喜欢
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 2019-10-09
    • 2022-07-20
    相关资源
    最近更新 更多