HtmlPage page = null; try { page = webClient.getPage(url); } catch (Exception e) { System.out.println("Get page error"); } JavaScriptJobManager manager = page.getEnclosingWindow().getJobManager(); while (manager.getJobCount() > 0) { Thread.sleep(1000); } System.out.println(page.asXml()); return page;
private static Scriptable getScope(final HtmlPage page, final DomNode node) { if (node != null) { return node.getScriptableObject(); } return page.getEnclosingWindow().getScriptableObject(); }
/** * {@inheritDoc} */ @Override public void showStatus(final String status) { // perhaps should we move status handling to WebWindow // on the other side this allows "orphaned" pages to be usable final Window window = (Window) htmlPage_.getEnclosingWindow().getScriptableObject(); window.setStatus(status); } }
private Scriptable getScope(final HtmlPage htmlPage, final DomNode htmlElement) { final Scriptable scope; if (htmlElement != null) { scope = htmlElement.getScriptObject(); } else { scope = (Window) htmlPage.getEnclosingWindow().getScriptObject(); } return scope; }
private Scriptable getScope(final HtmlPage htmlPage, final DomNode htmlElement) { final Scriptable scope; if (htmlElement != null) { scope = htmlElement.getScriptObject(); } else { scope = (Window) htmlPage.getEnclosingWindow().getScriptObject(); } return scope; }
private Scriptable getScope(final HtmlPage htmlPage, final DomNode htmlElement) { final Scriptable scope; if (htmlElement != null) { scope = htmlElement.getScriptObject(); } else { scope = (Window) htmlPage.getEnclosingWindow().getScriptObject(); } return scope; }
/** * {@inheritDoc} */ @Override public void showStatus(final String status) { // perhaps should we move status handling to WebWindow // on the other side this allows "orphaned" pages to be usable final Window window = (Window) htmlPage_.getEnclosingWindow().getScriptableObject(); window.setStatus(status); } }
private static Scriptable getScope(final HtmlPage page, final DomNode node) { if (node != null) { return node.getScriptableObject(); } return page.getEnclosingWindow().getScriptableObject(); }
/** * Returns a list containing all the frames (from frame and iframe tags) in this page. * @return a list of {@link FrameWindow} */ public List<FrameWindow> getFrames() { final List<FrameWindow> list = new ArrayList<FrameWindow>(); final WebWindow enclosingWindow = getEnclosingWindow(); for (final WebWindow window : getWebClient().getWebWindows()) { // quite strange but for a TopLevelWindow parent == self if (enclosingWindow == window.getParentWindow() && enclosingWindow != window) { list.add((FrameWindow) window); } } return list; }
/** * Returns a list containing all the frames (from frame and iframe tags) in this page. * @return a list of {@link FrameWindow} */ public List<FrameWindow> getFrames() { final List<FrameWindow> list = new ArrayList<FrameWindow>(); final WebWindow enclosingWindow = getEnclosingWindow(); for (final WebWindow window : getWebClient().getWebWindows()) { // quite strange but for a TopLevelWindow parent == self if (enclosingWindow == window.getParentWindow() && enclosingWindow != window) { list.add((FrameWindow) window); } } return list; }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final DomElement doc = page.getDocumentElement(); final Scriptable scriptable = page.getEnclosingWindow().getScriptableObject(); page.executeJavaScriptFunction(function_, scriptable, args_, doc); }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final HtmlElement doc = page.getDocumentElement(); final Scriptable scriptable = (Scriptable) page.getEnclosingWindow().getScriptObject(); page.executeJavaScriptFunctionIfPossible(function_, scriptable, new Object[0], doc); }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final HtmlElement doc = page.getDocumentElement(); final Scriptable scriptable = (Scriptable) page.getEnclosingWindow().getScriptObject(); page.executeJavaScriptFunctionIfPossible(function_, scriptable, new Object[0], doc); }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final HtmlElement doc = page.getDocumentElement(); final Scriptable scriptable = (Scriptable) page.getEnclosingWindow().getScriptObject(); page.executeJavaScriptFunctionIfPossible(function_, scriptable, new Object[0], doc); }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final DomElement doc = page.getDocumentElement(); final Scriptable scriptable = page.getEnclosingWindow().getScriptableObject(); page.executeJavaScriptFunction(function_, scriptable, args_, doc); }
/** * Executes the event on this object only (needed for instance for onload on (i)frame tags). * @param event the event * @return the result */ public ScriptResult executeEvent(final Event event) { if (eventListenersContainer_ != null) { final HtmlPage page = (HtmlPage) this.<DomNode>getDomNodeOrDie().getPage(); final Window window = (Window) page.getEnclosingWindow().getScriptObject(); return window.executeEvent(event, eventListenersContainer_); } return null; }
private Object[] convertScriptArgs(HtmlPage page, final Object[] args) { final Scriptable scope = (Scriptable) page.getEnclosingWindow().getScriptObject(); final Object[] parameters = new Object[args.length]; final ContextAction action = new ContextAction() { @Override public Object run(final Context context) { for (int i = 0; i < args.length; i++) { parameters[i] = parseArgumentIntoJavascriptParameter(context, scope, args[i]); } return null; } }; getWebClient().getJavaScriptEngine().getContextFactory().call(action); return parameters; }
/** * Implementation of the IE behavior #default#download. * @param uri the URI of the download source * @param callback the method which should be called when the download is finished * @see <a href="http://msdn.microsoft.com/en-us/library/ms531406.aspx">MSDN documentation</a> * @throws MalformedURLException if the URL cannot be created */ public void startDownload(final String uri, final Function callback) throws MalformedURLException { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); final URL url = page.getFullyQualifiedUrl(uri); if (!page.getWebResponse().getRequestSettings().getUrl().getHost().equals(url.getHost())) { throw Context.reportRuntimeError("Not authorized url: " + url); } final JavaScriptJob job = new DownloadBehaviorJob(url, callback); page.getEnclosingWindow().getJobManager().addJob(job, page); }
/** * Implementation of the IE behavior #default#download. * @param uri the URI of the download source * @param callback the method which should be called when the download is finished * @see <a href="http://msdn.microsoft.com/en-us/library/ms531406.aspx">MSDN documentation</a> * @throws MalformedURLException if the URL cannot be created */ public void startDownload(final String uri, final Function callback) throws MalformedURLException { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); final URL url = page.getFullyQualifiedUrl(uri); if (!page.getWebResponse().getRequestSettings().getUrl().getHost().equals(url.getHost())) { throw Context.reportRuntimeError("Not authorized url: " + url); } final JavaScriptJob job = new DownloadBehaviorJob(url, callback); page.getEnclosingWindow().getJobManager().addJob(job, page); }
private boolean isAlreadyLoadedByAncestor( final URL url, HtmlPage page ) { WebWindow window = page.getEnclosingWindow(); while (window != null) { if (url.sameFile(window.getEnclosedPage().getWebResponse().getWebRequest().getUrl())) { return true; } if (window == window.getParentWindow()) { window = null; } else { window = window.getParentWindow(); } } return false; }