Example usage for org.openqa.selenium WebDriverException WebDriverException

List of usage examples for org.openqa.selenium WebDriverException WebDriverException

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriverException WebDriverException.

Prototype

public WebDriverException(Throwable cause) 

Source Link

Usage

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public String getTitle() {
    try {/*from w  w  w .j  a  va  2 s.c om*/
        JSONObject cmd = new JSONObject();
        cmd.put("method", "Runtime.evaluate");
        cmd.put("params", new JSONObject().put("expression", "document.title;").put("returnByValue", true));
        JSONObject response = sendCommand(cmd);
        return cast(response);
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }
    /*String title = (String) executeScript("var state = document.title; return state",new JSONArray());
    return title;*/
}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public String getPageSource() {
    try {//from   w w w .j  a  v  a  2s. co m
        JSONObject cmd = new JSONObject();
        cmd.put("method", "Runtime.evaluate");
        cmd.put("params",
                new JSONObject().put("expression", "new window.XMLSerializer().serializeToString(document);")
                        .put("returnByValue", true));
        JSONObject response = sendCommand(cmd);
        return cast(response);
    } catch (Exception e) {
        throw new WebDriverException(e);
    }

}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public Object executeScript(String script, JSONArray args) {

    try {//w  ww  .  j  ava 2  s  .c  o m
        RemoteWebElement document = getDocument();
        RemoteWebElement window = context.getWindow();
        JSONObject cmd = new JSONObject();

        JSONArray arguments = new JSONArray();
        int nbParam = args.length();
        for (int i = 0; i < nbParam; i++) {
            Object arg = args.get(i);
            if (arg instanceof JSONObject) {
                JSONObject jsonArg = (JSONObject) arg;
                if (jsonArg.optString("ELEMENT") != null) {
                    // TODO use driver factory to check the  pageId
                    NodeId n = new NodeId(Integer.parseInt(jsonArg.optString("ELEMENT").split("_")[1]));
                    RemoteWebElement rwep = new RemoteWebElement(n, this);
                    arguments.put(new JSONObject().put("objectId", rwep.getRemoteObject().getId()));
                }
            } else if (arg instanceof JSONArray) {
                JSONArray jsonArr = (JSONArray) arg;
                // maybe by executing some JS returning the array, and using that result
                // as a param ?
                throw new WebDriverException("no support argument = array.");
            } else {
                arguments.put(new JSONObject().put("value", arg));
            }

        }

        if (!context.isOnMainFrame()) {
            arguments.put(new JSONObject().put("objectId", document.getRemoteObject().getId()));
            arguments.put(new JSONObject().put("objectId", window.getRemoteObject().getId()));

            String contextObject = "{'document': arguments[" + nbParam + "], 'window': arguments["
                    + (nbParam + 1) + "]}";
            script = "with (" + contextObject + ") {" + script + "}";

        }

        cmd.put("method", "Runtime.callFunctionOn");
        cmd.put("params",
                new JSONObject().put("objectId", document.getRemoteObject().getId())
                        .put("functionDeclaration", "(function() { " + script + "})")
                        .put("arguments", arguments).put("returnByValue", false));
        JSONObject response = sendCommand(cmd);
        checkForJSErrors(response);
        Object o = cast(response);
        return o;
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }

}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public void checkForJSErrors(JSONObject response) throws JSONException {
    if (response.optBoolean("wasThrown")) {
        JSONObject details = response.getJSONObject("result");
        String desc = details.optString("description");
        throw new WebDriverException("JS error :" + desc);
    }/*from  w w w  . jav a 2  s  .com*/
}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public <T> T cast(JSONObject response) {
    JSONObject body = null;/*from   w w w .jav  a  2  s. c  om*/
    try {
        body = response.has("result") ? response.getJSONObject("result") : response.getJSONObject("object");
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }

    if (body == null) {
        throw new RuntimeException("Error parsting " + response);
    }

    try {
        return cast_(body);
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }

}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

private void flagPageLoaded() {
    try {/*from w  w w. j  a  v a2  s  . c om*/
        JSONObject cmd = new JSONObject();
        cmd.put("method", "Runtime.evaluate");
        cmd.put("params", new JSONObject().put("expression", "window.top.iosdriver='" + context.getId() + "'"));
        sendCommand(cmd);
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }

}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public String getLoadedFlag() {
    JSONObject cmd = new JSONObject();
    try {/*from   w  w w.j  a  va 2  s .  co  m*/
        cmd.put("method", "Runtime.evaluate");
        cmd.put("params", new JSONObject().put("expression", "window.top.iosdriver"));
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }
    JSONObject response = sendCommand(cmd);
    return cast(response);
}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

private String getMainPageReadyState() {
    try {//from  w w  w. ja  v  a 2s  .  c om
        JSONObject cmd = new JSONObject();
        cmd.put("method", "Runtime.evaluate");
        cmd.put("params",
                new JSONObject().put("expression", "document.readyState;").put("returnByValue", true));
        JSONObject response = sendCommand(cmd);
        return cast(response);
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }
}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public void back() throws JSONException {
    try {// ww  w  . j  a v a  2 s. c  o  m
        String f = "(function() { var f=" + IosAtoms.BACK + "();})()";
        JSONObject cmd = new JSONObject();
        cmd.put("method", "Runtime.evaluate");
        cmd.put("params", new JSONObject().put("expression", f).put("returnByValue", true));
        JSONObject response = sendCommand(cmd);
        cast(response);
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }
}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public void forward() throws Exception {
    try {/*w  w  w  .j a  va 2 s .  c o  m*/
        String f = "(function() { var f=" + IosAtoms.FORWARD + "();})()";
        JSONObject cmd = new JSONObject();
        cmd.put("method", "Runtime.evaluate");
        cmd.put("params", new JSONObject().put("expression", f).put("returnByValue", true));
        JSONObject response = sendCommand(cmd);
        cast(response);
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }
}