swift - 有没有办法在 UITest 中使用 .selectedSegmentIndex 而不是 .buttons["name"]?
问题描述
在我的 UITests 中进行元素查询时,为了截取不同分段控件值的屏幕截图,在翻译开始起作用时会引发错误,因为我使用.buttons["name"]
,并且名称是英文并且没有按预期翻译。它是从故事板翻译过来的。所以我想找到一个更简单的解决方案。
我可以使用 .selectedSegmentIndex 而不是 UITest 中出现翻译错误的按钮名称,还是有其他方法可以解决此问题?
XCUIApplication().scrollViews
.children(matching: .other)
.element
.children(matching: .other)
.element(boundBy: 0)
.children(matching: .other)
.otherElements
.segmentedControls["MySegmentedControl"]
.buttons["name"] // How to add this value to be .selectedSegmentIndex = 1?
.tap()
解决方案
您可以使用以下方式访问指定索引处的元素element(boundBy:)
对于您的情况;
app.scrollViews
.segmentedControls
.buttons
.element(boundBy: 1)
.tap()
推荐阅读
- sqlite - MediaWiki 在尝试从安装到 docker conainer 的 sqlite db 中读取时引发 DBTransactionStateError
- hadoop - Hadoop 2.7.2 中的 TestDFSIO
- jquery - jQuery - animate().css() 完成
- python - 如何制作具有并行运行命令行工具的功能的python模块(不使用 if __name__ == '__main__': 所以它是可导入的)?
- python - sum函数如何在python中使用for循环
- reactjs - 反应状态:更新数组对象的索引而不显式指定键
- java - 如果我将 Mock 值设为私有,Mockito 是否需要使用反射?
- python - 抓取一些 Facebook 数据但不是全部?Scrapy/Splash/Python
- php - Laravel - 如何添加另一个联接以获取多个表
- php - 根据记录总数显示 owl-carousel 滑块?