如何获取与标识符匹配的元素数量,例如 XCUIQuery 返回的“fooImage”?

abl*_*arg 5 xcode-ui-testing uitest xcuitest

假设我有一个包含三个图像的表,它们accessiblityIdentifier设置为“fooImage”。

XCTAssertTrue(table["tableName"].images.count == 3)会起作用,但这很糟糕——如果有人添加了另一种图像类型怎么办?我想要标识符==“fooImage”的所有图像的计数。

XCUIApplication().images["fooImage"].count是一个编译失败Value of type 'XCUIElement' has no member 'count'

Tit*_*eul 10

在 an 上使用下标XCUIElementQuery会给你一个XCUIElement没有count属性的。你想用countXCUIElementQuery这样的。

XCUIApplication().images.matching(identifier: "fooImage").count
Run Code Online (Sandbox Code Playgroud)