问题:
我司的 ios app,主页面上的功能,为了做成卡片式的效果,采用了自定义的 UIViewController like this
用 appium inspector 无法获取元素,page source 打出来没有,ui automation 录制也录不到,简直愁死了。如果旁边有条狗。。。就。。扯远了。。言归正传,附上解决方法。
解决方法:

iOS Support

See Running on OS X: iOS for iOS requirements and setup instructions.

Versions: 7.1, 8.0, 8.1, 8.2, 8.3, 8.4, 9.0, 9.1 and 9.2 Devices:
iPhone Simulator, iPad Simulator, and real iPhones and iPads Native
app support: Yes, with debug version of .app (simulator), or
correctly-signed .ipa (real devices). Underlying support is provided
by Apple's UIAutomation framework. Mobile web support: Yes, via
automation of mobile Safari. For real devices,
ios-webkit-remote-debugger is required, and automation of native
aspects of the Safari interface is not possible. See the mobile web
doc for instructions. Hybrid support: Yes. For real devices,
ios-webkit-remote-debugger is required. See the hybrid doc for
instructions. Support for automating multiple apps in one session: No
Support for automating multiple devices simultaneously: No Support for
automating vendor-provided or third-party apps: Only vendor-provided
apps (Preferences, Maps, etc...), and only on the simulator Support
for automating custom, non-standard UI controls: Minimal. You need to
set accessibility information on the control which enables some basic
automation.

appium 的 github 上更新了关于自定义,非标准控件的内容,原为不支持,现在更新为可以通过设置 accessibility 信息来做基本的自动化操作。
在群里经过恒温的点播,动手打开源码,试验一番。
在.storyboard 中找到之前让我蛋疼让我忧无法定位到的控件,查看它的属性。这个 accessbility 不就是我需要的 accessbility info 吗,不妨一试,将属性改为上图所示。build 一把,跑起来,用 inspector 查看,之前无法获取的元素都都出现了。like this
可以看到该 view 下面的元素,都可以被识别到了。问题又来了,被识别出来的其它元素,name 和 label 属性也有值,它们并不是在 accessbility 里设置的,如果是的话也不会造成我遇到的问题了,那它们是在哪里被赋值的?又查了一把,发现是在源码中赋值的。还存在一些问题,不过至少能识别到自定义 UIViewController 下的元素了。还是比较欣慰的,在此分享下我的解决方法。


↙↙↙阅读原文可查看相关链接,并与作者交流