![](/img/trans.png)
[英]How to test Webview is loaded or not without staticTexts in XCTest in swift
[英]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.