ios - 如何访问嵌套在 UITests 的 MkMapView 中的 UIStackView 中的元素?
问题描述
我想为内部的视图编写 UIUIStackView
测试MKMapView
。这是 MWE 的一个片段。我创建了一个MKMapView
添加了UIStackView
两个UIView
s 作为子视图的 a。
let map = MKMapView()
let view1 = UIView()
let view2 = UIView()
let stackView = UIStackView()
stackView.addArrangedSubview(view1)
stackView.addArrangedSubview(view2)
map.addSubview(stackView)
view.addSubview(map)
我accessibilityIdentifier
为每个元素声明了一个并将isAccessibilityElement
属性设置为true。
view1.accessibilityIdentifier = "view1"
view2.accessibilityIdentifier = "view2"
stackView.accessibilityIdentifier = "stackView"
view1.isAccessibilityElement = true
view2.isAccessibilityElement = true
stackView.isAccessibilityElement = true
但是,在应用程序元素子树中没有可见的堆栈视图的子视图,也无法访问它们。您可以看到UIStackView
带有标识符“stackView”的 ,但看不到UIViews
.
Element subtree:
→Application, 0x6000030080e0, pid: 11856, label: 'UITestWithStackView'
Window (Main), 0x600003009500, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003009420, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003009340, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003009260, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003009180, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x6000030090a0, {{7.0, 348.0}, {400.0, 200.0}}, identifier: 'stackView'
Other, 0x600003008fc0, {{0.0, 0.0}, {414.0, 896.0}}
Map, 0x600003008ee0, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003008e00, {{0.0, 0.0}, {414.0, 896.0}}
Link, 0x600003008d20, {{375.4, 841.3}, {28.6, 10.7}}, label: 'Legal'
Window, 0x600003008c40, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003008b60, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003008a80, {{0.0, 0.0}, {414.0, 896.0}}
这种行为是否有任何已知的解决方法?
解决方案
嵌套堆栈视图有同样的问题。在我的情况下,它是一个带有标签的stackView,它嵌套在另外两个堆栈中。我需要访问标签。使用 AccessiblityElements 有助于访问较低堆栈中的元素。
rootStackView.accesibilityElements[nestedElementsThatNeedToMakeAccessible]
如果我正确理解你的情况,试试这个
stackView.accessibilityElements[view1, view2]
map.accessibilityElements[stackView]
推荐阅读
- python - 使用 tkinter 的度数计算器
- python - 无法将 (N, 1) 数组转换为 (N,)
- html - 将引导菜单放置在样式化的 div 中
- java - SwitchPreference 的图形没有变化
- php - Laravel:控制器是否需要扩展 Illuminate\Routing\Controller?为什么?
- mysql - 带有计数和连接表的 SQL 查询
- javascript - 当组件的道具更新时动画
- ruby-on-rails - jquery 在生产中不像在开发中那样工作
- python - 如何使用正则表达式从此有效负载中提取字段?
- python - 在 folium 中显示栅格数据(不处理数据值)。