
例如,如果导航栏标题是“Rent PropertIEs”,那么我可以这样匹配:
XCTAssert(XCUIApplication().staticTexts["Rent PropertIEs"].exists)
但是,这有两个问题:
>如果文本不在导航栏中,它仍将匹配
>它完全匹配,而我希望能够匹配一个子字符串,如“租”
如何才能做到这一点?
解决方法 对于匹配子字符串Rent,您可以使用以下代码:XCUIApplication().staticTexts.matchingPredicate(nspredicate(format: "label CONTAINS 'Rent'")).elementBoundByIndex(0)//it may contains one or more element with substring Rent.//you have to find out which element index you want in deBUG mode using p print() options.
对于第一个选项,当元素显示或不显示时,肯定必须存在差异.你必须在调试模式下使用po或p print选项找出它.
例如,可能计数不同或元素不可命中等等….
你可以尝试使用:
let app = XCUIApplication()XCTAssert(app.staticTexts["Rent PropertIEs"].exists)or let app = XCUIApplication()app.staticTexts["Rent PropertIEs"].hittableorlet app = XCUIApplication()app.staticTexts["Rent PropertIEs"].enabledor app.staticTexts.matchingIDentifIEr("Rent PropertIEs").count//take count while showing the text and take the count while not showing the text 总结 以上是内存溢出为你收集整理的ios – XCTest – 如何在导航栏标题中查询子字符串全部内容,希望文章能够帮你解决ios – XCTest – 如何在导航栏标题中查询子字符串所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)