webClient.setAjaxController(new NicelyResynchronizingAjaxController()); // Edit some js, prior to execution webClient.setScriptPreProcessor(new JavascriptPreProcessor() { ... } ); // Avoid throwing errors on JS execution webClient.setThrowExceptionOnScriptError(false); // Avoid throwing errors because of wrong response codes webClient.setThrowExceptionOnFailingStatusCode(false);
/** * Creates an instance. */ public NicelyResynchronizingAjaxController() { init(); }
/** * Resynchronizes calls performed from the thread where this instance has been created. * * {@inheritDoc} */ @Override public boolean processSynchron(final HtmlPage page, final WebRequest settings, final boolean async) { if (async && isInOriginalThread()) { LOG.info("Re-synchronized call to " + settings.getUrl()); return true; } return !async; }
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
/** * Creates an instance. */ public NicelyResynchronizingAjaxController() { init(); }
/** * Resynchronizes calls performed from the thread where this instance has been created. * * {@inheritDoc} */ @Override public boolean processSynchron(final HtmlPage page, final WebRequestSettings settings, final boolean async) { if (async && isInOriginalThread()) { LOG.info("Re-synchronized call to " + settings.getUrl()); return true; } return !async; }
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
/** * Creates an instance. */ public NicelyResynchronizingAjaxController() { init(); }
/** * Resynchronizes calls performed from the thread where this instance has been created. * * {@inheritDoc} */ @Override public boolean processSynchron(final HtmlPage page, final WebRequestSettings settings, final boolean async) { if (async && isInOriginalThread()) { LOG.info("Re-synchronized call to " + settings.getUrl()); return true; } return !async; }
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
/** * Creates an instance. */ public NicelyResynchronizingAjaxController() { init(); }
/** * Resynchronizes calls performed from the thread where this instance has been created. * * {@inheritDoc} */ @Override public boolean processSynchron(final HtmlPage page, final WebRequestSettings settings, final boolean async) { if (async && isInOriginalThread()) { LOG.info("Re-synchronized call to " + settings.getUrl()); return true; } return !async; }
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
/** * Creates an instance. */ public NicelyResynchronizingAjaxController() { init(); }
/** * Resynchronizes calls performed from the thread where this instance has been created. * * {@inheritDoc} */ @Override public boolean processSynchron(final HtmlPage page, final WebRequest settings, final boolean async) { if (async && isInOriginalThread()) { LOG.info("Re-synchronized call to " + settings.getUrl()); return true; } return !async; }
String strURL = "https://www.checkmytrip.com" ; java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF); java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF); try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_31)) { webClient.setAjaxController(new NicelyResynchronizingAjaxController()); HtmlPage myPage = ((HtmlPage) webClient.getPage(strURL)); webClient.waitForBackgroundJavaScript(10 * 1000); String theContent = myPage.asXml(); System.out.println(theContent); }
/** * Custom deserialization logic. * @param stream the stream from which to read the object * @throws IOException if an IO error occurs * @throws ClassNotFoundException if a class cannot be found */ private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); init(); }
@Override protected WebClient modifyWebClient(WebClient client) { client.setAjaxController(new NicelyResynchronizingAjaxController()); //Disables stuff like this "com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'." if (!this.debug) { client.setIncorrectnessListener((message, origin) -> {}); } return client; } }
/** * Custom deserialization logic. * @param stream the stream from which to read the object * @throws IOException if an IO error occurs * @throws ClassNotFoundException if a class cannot be found */ private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); init(); }
@Override protected WebClient modifyWebClient(WebClient client) { client.setAjaxController(new NicelyResynchronizingAjaxController()); //Disables stuff like this "com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify WARNING: Obsolete content type encountered: 'text/javascript'." if (!this.debug) { client.setIncorrectnessListener(new IncorrectnessListener() { @Override public void notify(String message, Object origin) { } }); } return client; } }