首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法在.selectedSegmentIndex中使用.buttons而不是.buttons["name"]?

有没有办法在.selectedSegmentIndex中使用.buttons而不是.buttons["name"]?
EN

Stack Overflow用户
提问于 2020-07-21 07:54:10
回答 1查看 207关注 0票数 1

在UITests中执行元素查询时,要获取不同分段控件值的屏幕截图,在使用.buttons["name"]时会引发一个错误,并且名称是英文的,没有按预期翻译。它已经从故事板上翻译出来了。所以我想找一个更简单的解决方案。

我可以使用.selectedSegmentIndex代替UITest中存在翻译错误的按钮名,或者有其他方法解决这个问题吗?

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-21 11:58:56

可以使用element(boundBy:)在指定索引处访问元素。

为你的案子;

代码语言:javascript
复制
app.scrollViews
.segmentedControls
.buttons
.element(boundBy: 1)
.tap()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63009901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档