[英]How to print all the staticTexts in XCUITest
I have used app.staticTexts["String"].tap()
to tap on a button containing that string which is working completely fine.我已经使用
app.staticTexts["String"].tap()
来点击包含该字符串的按钮,该按钮工作正常。
But the problem here is that i want to print all the static
texts which are present on that page, how can i do it in XCUITest
?但这里的问题是我想打印该页面上存在的所有
static
文本,我该如何在XCUITest
执行此XCUITest
?
My aim here is to iterate through all the static
texts present on the page and then add an if
condition on my expected text.我的目标是遍历页面上存在的所有
static
文本,然后在我预期的文本上添加一个if
条件。
You can use something like that:你可以使用这样的东西:
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")
}
}
I suppose the text is present in the identifier
attribute of the staticText
element.我想文本存在于
staticText
元素的identifier
属性中。 You can try the following您可以尝试以下操作
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.