Macaca 运行官方例子 sample-java-master 下面的 DesktopSampleTest 报 java.lang.Integer cannot be cast to java.lang.String

逝去的青春 · 2018年05月29日 · 最后由 TerryGee 回复于 2018年06月07日 · 1348 次阅读

求助,最近要入自动化 ui 的坑,选定了 Macaca,运行官方例子报错 java.lang.Integer cannot be cast to java.lang.String,查看了问题代码是:

private boolean findElement(JSONObject jsonObject) throws Exception {
        jsonObject.put("sessionId", contexts.getSessionId());
        JSONObject response = (JSONObject) utils.request("POST", DriverCommand.FIND_ELEMENT, jsonObject);
        JSONObject tmpElement = (JSONObject) response.get("value");
        String elementId = (String) tmpElement.get("ELEMENT"); --问题代码地方
        if (elementId != null) {
            // the element exists
            // contexts.setElementId(elementId);
            // fix bug:The new element covers the old element
            element = new Element(elementId, contexts);
            return true;
        } else {
            // the element does not exist
            return false;
        }

    }

这个怎么破。。。

共收到 3 条回复 时间 点赞

这个是很基本的 Java 问题吧,Integer 转 String 用 Integer.toString(),不过官方 example 不可能反这么低级的错误啊,你可以看看 tmpElement.get("ELEMENT") 返回的是否是 int 类型

cookie 回复

贴的这个是 MacacaClient 文件里面的代码。

这个调试的时候,看过返回是 int。

同样遇到这个问题,已给 MacacaClient 项目提 Issue,临时解决方法:用 Git 克隆 MacacaClient 项目,改一下出错的源码吧

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