![](/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.