簡體   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