iOS   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 在XCode中的UI测试期间无法访问自定义视图大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的应用程序中,有一个标签包含在一个简单的视图中.
该视图有一个水龙头识别器,它会触发一个功能(“为什么不使用一个按钮?”你可能会问……我们必须执行一些时髦的动画,这是我们最好的布局).问题是我无法访问此视图以模拟其上的点击.
我可以使用app.staticText [“输入名称…”]访问标签,但是如果我点击它(希望传播到父视图).
记录我点击标签的会话将产生app.staticText [“输入名称…”]命令,但播放它产生相同的错误.

我已经尝试在Storyboard中激活该视图的辅助功能单元并为其提供一个ID,以便使用此命令获取它:

app.windows.elementMatchingType(.Any,identifier: "MyView")

但是一旦这个标志被检查并且我运行我的测试,应用程序就会进入一种循环循环,一遍又一遍地显示这个消息:

Find: Elements matching preDicate '"MyView" IN identifiers'

此视图不在表格内,而是在主视图中.我怎样才能访问它?

编辑1:
这是app.DebugDescription()的输出(感谢@Che的建议):

Element subtree:
 →Application 0x14e7e300: {{0.0,0.0},{320.0,568.0}},label: 'MyApp'
    Window 0x14dbfef0: Main Window,{{0.0,568.0}}
      Other 0x14dc0a40: Traits: 8589934592,568.0}}
        Other 0x14dc0ff0: Traits: 8589934592
        Other 0x14eb4f50: Traits: 8589934592,568.0}}
          Other 0x14eb53d0: Traits: 8589934592
          Button 0x14eb5940: Traits: 8589934593,{{12.0,26.0},{30.0,30.0}},label: 'home hamburger'
            Image 0x14eb5f00: Traits: 8589934596,{{16.0,30.0},{22.0,22.0}},identifier: 'home_hamburger'
          Other 0x14eb64c0: Traits: 8589934592,109.0},459.0}}
          Other 0x14eb6a20: Traits: 8589934592,167.0},{288.0,84.0}}
          Image 0x14eb6f80: Traits: 8589934596,{{59.0,184.0},{201.0,50.0}},identifier: 'main_logo'
          Other 0x14eb4850: Traits: 8589934592,254.0},60.0}}
            StaticText 0x14eb79e0: Traits: 8589934656,{{57.0,264.0},{160.0,40.0}},label: 'Enter name...'
            Image 0x14eb7f90: Traits: 8589934596,{{31.0,275.0},{18.0,18.0}},identifier: 'SearchIcon'
            Other 0x14eb8530: Traits: 8589934592,274.0},{2.0,20.0}}
          Other 0x14eb8ac0: Traits: 8589934592,262.0},44.0}}
            Image 0x14eb9060: Traits: 8589934596,44.0}}
            SearchField 0x14eb9610: Traits: 146029151232,{{24.0,270.0},{272.0,28.0}}
          Other 0x14eb9bc0: Traits: 8589934592
        Other 0x14eba170: Traits: 8589934592
    Window 0x14eba730: {{0.0,568.0}}
      StatusBar 0x14eBACa0: {{0.0,20.0}}
        Other 0x14ebb220: {{0.0,20.0}}
        Other 0x14ebb7b0: {{0.0,20.0}}
          Other 0x14ebbd50: Traits: 8388608,{{6.0,{35.0,20.0}},label: '3 of 5 bars,signal strength'
          Other 0x14ebc330: Traits: 8388608,{{44.0,{73.0,label: 'vodafone UK network'
          Other 0x14ebc8c0: Traits: 8388608,{{122.0,{13.0,label: '3 of 3 Wi-Fi bars',value: SSID
          Other 0x14ebce50: Traits: 8389120,{{146.0,{32.0,label: '11:34'
          Other 0x14ebd3d0: Traits: 8388608,{{282.0,{33.0,label: '100% battery power,Charging'
Path to element:
 →Application 0x14e7e300: {{0.0,label: 'MyApp'
Query chain:
 →Find: Target Application 0x14ea2c00
  Output: {
    Application 0x14e7e300: {{0.0,label: 'MyApp'
  }

解决方法

根据您提供的日志输出,没有MyView标识符的视图. 您可以在accessibilityIdentifier属性的帮助下进行设置.

大佬总结

以上是大佬教程为你收集整理的ios – 在XCode中的UI测试期间无法访问自定义视图全部内容,希望文章能够帮你解决ios – 在XCode中的UI测试期间无法访问自定义视图所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。