调用方法 Element.getProperty("size"),Element.getProperty("origin"),Element.getRect() 都提示 unknown command

macaca doctor 结果:

macaca-doctor version: 1.0.28


Node.js checklist:

node env: D:\Softwares\NodeJs\node.exe
node version: v4.6.0

Android checklist:

JAVA version is `1.8.0_66`
JAVA_HOME is set to `C:\Program Files\Java\jdk1.8.0_66`
ANDROID_HOME is set to `D:\Softwares\Android\AndroidSDK`
Platforms is set to `D:\Softwares\Android\AndroidSDK\platforms\android-23`
Android tools is set to `D:\Softwares\Android\AndroidSDK\tools\android.bat`
ADB tool is set to `D:\Softwares\Android\AndroidSDK\platform-tools\adb.exe`
ANT_HOME is set to `D:\Softwares\apache-ant-1.9.7`

Installed driver list:

android: 1.1.16

macacaclient 版本:

<dependency>
  <groupId>macaca.webdriver.client</groupId>
  <artifactId>macacaclient</artifactId>
  <version>2.0.1</version>
</dependency>

软件为 Hybrid App,要获取大小是元素位于 webview 中

测试代码:

public class App {
    public static void main(String[] args) {
        MacacaClient driver = new MacacaClient();

        String platform = "android";
        JSONObject props = new JSONObject();
        props.put("platformName", platform);
        props.put("app", "C:/Users/Administrator/Desktop/AUT.1.0.6.apk");
        props.put("reuse", 3);
        JSONObject desiredCapabilities = new JSONObject();
        desiredCapabilities.put("desiredCapabilities", props);
        try {
            driver.initDriver(desiredCapabilities);
            driver.context("NATIVE_APP");
            System.err.println(driver.currentContext());
            JSONArray arr = driver.contexts();
            arr.remove("NATIVE_APP");

            for(int i = 0; i < arr.size(); ++i) {
                driver.context(arr.getString(i));
                String a = driver.url();
                if(a.endsWith("ptjy_header.html")) {
                    break;
                }
            }
            System.err.println(driver.url());
            System.err.println(driver.currentContext());
            Element e = driver.elementByXPath("//label[text()='买入']");
            System.err.println(e.getRect());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                driver.quit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}


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