Xcode ui测试:staticTexts以
问题描述:
我想检查我的ui上是否存在以前缀开头的元素.如何在Xcode 7 UI测试中实现它?
I want to check if an element on my ui which start with a prefix is present. How is it possible to implement it in Xcode 7 UI Tests?
app.tables["AAA"].staticTexts["Fax: 0049XXXXXXXX"].exists
我在表视图单元格中有三个元素,只有一个(第三个或最后一个)以前缀Fax:0049开头.如何检查此元素的存在?
I have three element into a tableview cell and only one (the third or last one) starts with the prefix Fax: 0049. How can i check the present of this element?
我尝试过
app.tables["AAA"].cells.staticTexts.elementBoundByIndex(2).exists
但没有,有什么主意吗?干杯
But nothing, some ideas? Cheers
答
您可以使用 BEGINSWITH
谓词检查元素是否以前缀开头.
You can use a BEGINSWITH
predicate to check if an element starts with a prefix.
let app = XCUIApplication()
let faxPredicate = NSPredicate(format: "label BEGINSWITH 'Fax: '")
let faxLabel = app.staticTexts.element(matching: faxPredicate)
XCTAssert(faxLabel.exists)
这里是一个工作示例,用于选择具有不同 BEGINSWITH
谓词
Here's a working example for selecting elements with a different BEGINSWITH
predicate, a picker with multiple wheels.