@Override public void init() { String jsCallbackName = getParameter("applet_ready_callback"); JSObject jsObject = JSObject.getWindow(this); jsObject.eval(jsCallbackName + "()"); }
@Override public void init() { // some code JSObject jsObject = JSObject.getWindow(this); jsObject.eval("your javascript"); }
String callbackFunction; public void RegisterCallback(String functionName) { callbackFunction = functionName; } void UseCallbackFunction() { if (callbackFunction == null) return; JSObject win = (JSObject) JSObject.getWindow(this); win.eval(callbackFunction); }
public void jsAppletCall() { // do you java stuff here // then // call the javascript from the applet using the JSOBject JSObject win = JSObject.getWindow(this); win.eval("callJSFromMyAppletMessage();"); }
public void init() { JSObject document = JSObject.getWindow(this); String evalString = "document.getElementById('secondAppletPanel').innerHTML = "; document.eval(evalString + secondAppletHtmlString); }
JSObject win = JSObject.getWindow(this); win.eval("document.getElementById('#applet').innerHTML=''", null);
JSObject jsWin = getHostServices().getWebContext(); if (jsWin != null) { jsWin.eval("show_alert();"); }
Executor exe = Executors.newSingleThreadExecutor(); final JSObject page = JSObject.getWindow(applet); if (page == null) { /* Break here, no connection could be made */ } final String javascriptFunction = "yourJavaScriptFunction()"; executor.execute(new Runnable() { public void run() { page.eval(javascriptFunction); } });
/** * {@inheritDoc} */ @Override public String getCssValue(final String name) { return AppThread.exec(contextItem.statusCode, () -> { validate(false); return cleanUpCssVal((String) (node.eval(new StringBuilder() .append("var me = this;") .append("(function(){") .append(" return window.getComputedStyle(me).getPropertyValue('") .append(name) .append("');") .append("})();").toString()))); }); }
/** * {@inheritDoc} */ @Override public boolean isDisplayed() { return AppThread.exec(contextItem.statusCode, () -> { validate(false); return (Boolean) node.eval(IS_VISIBLE); }); }
if (callback) { argList.add(null); node.eval(new StringBuilder().append("(function(){") .append("this.").append(jsNames.callback).append(" = function(){") .append(jsNames.callbackVal).append(" = arguments && arguments.length > 0? arguments[0] : null;") .append("};").toString()); } else { node.eval(new StringBuilder().append("this.").append(jsNames.exec).append(" = function(){") .append("return (function(){").append(script).append("}).apply(this, arguments);") .append("};").toString()); return t; } finally { node.eval("delete " + "this." + jsNames.exec + ";"); if (callback) { node.eval("delete " + "this." + jsNames.callback + ";");
return window.eval(script); } catch (Throwable throwable) { throw new UnsupportedOperationException(throwable);
/** * Evaluates a script in the page context and returns the result. * * @param script * @param application */ public static Object eval(String script, Application application) { if (application == null) { throw new IllegalArgumentException("application is null."); } HostApplet applicationHostApplet = null; for (HostApplet hostApplet : hostApplets) { if (hostApplet.getApplication() == application) { applicationHostApplet = hostApplet; break; } } if (applicationHostApplet == null) { throw new IllegalArgumentException("No applet is hosting the given application."); } try { JSObject window = JSObject.getWindow(applicationHostApplet); return window.eval(script); } catch (Throwable throwable) { throw new UnsupportedOperationException(throwable); } }
sb.append("{\n"); final JSObject js = (JSObject) o; final JSObject keys = (JSObject) js.eval(getKeys); boolean needComma = false; for (int i = 0;; i++) {
/** * {@inheritDoc} */ @Override public String getText() { return AppThread.exec(contextItem.statusCode, () -> { validate(false); if ((Boolean) node.eval(IS_VISIBLE)) { String textAttribute = "TEXTAREA".equals(node.getMember("tagName")) ? "textContent" : "innerText"; Object text = node.getMember(textAttribute); return text instanceof String ? ((String) text).trim() : ""; } return ""; }); }
/** * {@inheritDoc} */ @Override public void sendKeys(final CharSequence... keys) { AppThread.exec(contextItem.statusCode, () -> { validate(true); node.eval(SCROLL_INTO_VIEW); node.call("focus"); return null; }); final boolean fileChooser = node instanceof HTMLInputElement && "file".equalsIgnoreCase(getAttribute("type")); if (fileChooser) { click(); } contextItem.context.get().robot.get().keysType(keys); if (fileChooser) { contextItem.context.get().robot.get().typeEnter(); } }
contextItem.statusCode, () -> { validate(false); return node.eval("(function(){return this." + jsNames.callbackVal + ";})();"); }); if (!(result instanceof String) || !"undefined".equals(result.toString())) { contextItem.statusCode, () -> { validate(false); node.eval("delete " + jsNames.callbackVal + ";"); return null; });
/** * {@inheritDoc} */ @Override public Point locate() { AppThread.exec(contextItem.statusCode, () -> { validate(false); node.eval(SCROLL_INTO_VIEW); return null; }); return AppThread.exec(contextItem.statusCode, () -> { validate(true); JSObject obj = (JSObject) node.call("getBoundingClientRect"); double y = Double.parseDouble(obj.getMember("top").toString()); double x = Double.parseDouble(obj.getMember("left").toString()); y = y < 0d ? 0d : y; x = x < 0d ? 0d : x; final org.openqa.selenium.Point frameLocation = contextItem.selectedFrameLocation(); return new Point((int) Math.rint(x) + 1 + frameLocation.getX(), (int) Math.rint(y) + 1 + frameLocation.getY()); }); }