使用Xcode 11与iPhone 11模拟器。试图在Spotlight搜索中输入一些文本:
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springboard.swipeDown()
let spotlightSearchField = springboard.searchFields["SpotlightSearchField"]
spotlightSearchField.typeText("Some text")无法找到具有可访问性标识符SpotlightSearchField的元素,尽管Spotlight搜索面板是可见的。如果我调用debugDescription,元素树中也不存在。DebugDescription输出不包含任何带有聚光灯和siri建议的下拉面板元素--仅包含主屏幕元素。
但是AccessibilityInspector可以找到聚光灯搜索字段并显示它的标识符。

我可以用代码访问这个字段吗?
发布于 2020-03-24 19:16:37
SpotlightSearchField是Spotlight的一部分,而不是SpringBoard。
您应该像这样与它交互:
let spotlight = XCUIApplication(bundleIdentifier: "com.apple.Spotlight")
let spotlightSearchField = spotlight.textFields["SpotlightSearchField"]
spotlightSearchField.typeText("Some text")祝好运!
https://stackoverflow.com/questions/60775901
复制相似问题