bat*_*str 2 ios xctest xcode-ui-testing
在 XCTest 中,有一种方法可以按类型获取所有 UI 元素,然后按 AccessibilityIdentifier 进行过滤,例如:
app.buttons[someID]
Run Code Online (Sandbox Code Playgroud)
但是如果我不知道视图的类型怎么办?如果我正在寻找 UIView,我可以写:
app.otherElements[someID]
Run Code Online (Sandbox Code Playgroud)
但这不包括 UIButton 视图。
我可以通过连续调用所有方法(staticTexts、textViews、buttons、otherElements 等)来实现这一点,但有些东西告诉我它的性能不是很好,因为类型列表很大。
有没有通用的方法?
Ole*_*tha 10
您可以使用后代(匹配 :)来查找任何类型的视图。
let app = XCUIApplication()
let element = app.descendants(matching: .any)["someID"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1227 次 |
| 最近记录: |