自动化测试工具 求助!关于 android 抓取 ui 所有控件 id 并截图时报 Only the original thread that created a view hierarchy can touch its views.

基拉 · 2015年03月04日 · 最后由 基拉 回复于 2015年03月04日 · 1290 次阅读

我们通过 athrun 自带 ViewUtils 中获取当前 ui 所有 views 再根据这些 views 截出控件的图片

代码如下:

for (int a = 0;a < ViewUtils.getAllViews(true).size(); a++) {

/************抓取ID**********/
            try {
                        takeScreenShot(ViewUtils.getAllViews(true).get(a),
                                "/sdcard/wa/", ViewUtils.getAllViews(true).get(a)
                                .getId());

                TimeUnit.SECONDS.sleep(3);
            } catch (NullPointerException e) {
                System.out.println("----------");
            }

但是发现现在有部分 apk 的 ui 更新不在主线程,是在子线程中更新,导致我们程序抓取 id 时报 Only the original thread that created a view hierarchy can touch its views. 找了个 android 开发问了下,可能是大部分 ui 是在主线程更新,有一些图片可能是在子线程里更新
请教下各位大神有什么解决方法么?或者说换种什么更好方法来抓取 ui 中控件的好方法?

共收到 3 条回复 时间 点赞

@seveniruby

另外发帖请用代码块。

这个应该是动态加载 ui 本身不支持,需要自己调整,我记得 q 博有一篇文章里面写了 你可以去翻翻看

@kasi 好的 我去找找 谢啦

4楼 已删除
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册