繁体   English   中英

如何打印 XCUITest 中的所有静态文本

[英]How to print all the staticTexts in XCUITest

我已经使用app.staticTexts["String"].tap()来点击包含该字符串的按钮,该按钮工作正常。
但这里的问题是我想打印该页面上存在的所有static文本,我该如何在XCUITest执行此XCUITest
我的目标是遍历页面上存在的所有static文本,然后在我预期的文本上添加一个if条件。

你可以使用这样的东西:

    for staticText in app.staticTexts.allElementsBoundByIndex {
        if staticText.label == "test" {

        }
    }
//Returns all the labels,buttons, textfield,images in the page with its  name.
//Just change the element name in loop according to the need.




 for staticText in  app.staticTexts.allElementsBoundByIndex{

            if staticText != nil{
                print(staticText.label)
            }else{
                print("No static text found")
            }

        }

我想文本存在于staticText元素的identifier属性中。 您可以尝试以下操作

for i in 0..<app.staticTexts.count {
    let text = app.staticTexts.element(boundBy: i).identifier
    print(text)
    if text == "Your String" {
        // Your code
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM