【发布时间】:2018-05-14 18:54:56
【问题描述】:
我收到一个错误
No matches found for Find: Descendants matching type NavigationBar from input {(
Application, 0x60400019b790, pid: 20515, label: '<appname>'
)}
但是代码是由 XCUITest 的录制功能生成的,所以我不明白为什么它找不到导航栏。我添加了一个accessibilityIdentifier,它是一个名为dashboardNavBar 的本地化字符串,尝试使用它来查找它,但我无法查询它。我正在使用的当前代码是:
func testLoginLogout() {
let app = XCUIApplication()
//login credentials and other code that takes me to dashboard of app
app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
app.sheets["Do you want to Logout ?"].buttons["OK"].tap()
}
app.navigationBars... 行是引发上述错误的行。我希望有人能告诉我为什么它无法找到此导航栏或任何问题,以及如何使用accessibilityIdentifier 修复它或解决它。谢谢。
【问题讨论】:
-
记录的代码说你要点击的元素是一个按钮。您可以像 app.buttons["AccessibilityID"].tap() 一样直接点击该按钮。否则你可以通过调试模式找到它并输入 po app.buttons.debugdescription |然后它将打印所有按钮。然后你也可以通过 app.buttons.element(boundBy : indexofSpecificelement).tap() 访问元素。让我知道你的发现。