public HtmlUnitDriver(BrowserVersion version) { this.version = version; webClient = createWebClient(version); webClient.addWebWindowListener(new WebWindowListener() { private boolean waitingToLoad;
/** Initializes the web client to wait for, registering opened windows and * listening for new windows. * @param theClient Web client to wait. Cannot be null. */ private void initialize(final WebClient theClient) { theClient.addWebWindowListener(webWindowListener); theClient.getOptions().setThrowExceptionOnScriptError(false); theClient.setJavaScriptErrorListener(javaScriptErrorListener); for (WebWindow webWindow : theClient.getWebWindows()) { if (!windows.contains(webWindow) && webWindow.getScriptObject() != null) { windows.add(webWindow); } } }
/** * Generic initialization logic used by all constructors. This method does not perform any * parameter validation; such validation must be handled by the constructors themselves. * @param browserVersion the browser version to simulate * @param proxyConfig the proxy configuration to use */ private void init(final BrowserVersion browserVersion, final ProxyConfig proxyConfig) { homePage_ = "http://www.gargoylesoftware.com/"; browserVersion_ = browserVersion; proxyConfig_ = proxyConfig; try { scriptEngine_ = createJavaScriptEngineIfPossible(this); } catch (final NoClassDefFoundError e) { scriptEngine_ = null; } // The window must be constructed AFTER the script engine. addWebWindowListener(new CurrentWindowTracker()); currentWindow_ = new TopLevelWindow("", this); fireWindowOpened(new WebWindowEvent(currentWindow_, WebWindowEvent.OPEN, null, null)); }
/** * Generic initialization logic used by all constructors. This method does not perform any * parameter validation; such validation must be handled by the constructors themselves. * @param browserVersion the browser version to simulate * @param proxyConfig the proxy configuration to use */ private void init(final BrowserVersion browserVersion, final ProxyConfig proxyConfig) { homePage_ = "http://www.gargoylesoftware.com/"; browserVersion_ = browserVersion; proxyConfig_ = proxyConfig; try { scriptEngine_ = createJavaScriptEngineIfPossible(this); } catch (final NoClassDefFoundError e) { scriptEngine_ = null; } // The window must be constructed AFTER the script engine. addWebWindowListener(new CurrentWindowTracker()); currentWindow_ = new TopLevelWindow("", this); fireWindowOpened(new WebWindowEvent(currentWindow_, WebWindowEvent.OPEN, null, null)); }
/** * Generic initialization logic used by all constructors. This method does not perform any * parameter validation; such validation must be handled by the constructors themselves. * @param browserVersion the browser version to simulate * @param proxyConfig the proxy configuration to use */ private void init(final BrowserVersion browserVersion, final ProxyConfig proxyConfig) { homePage_ = "http://www.gargoylesoftware.com/"; browserVersion_ = browserVersion; proxyConfig_ = proxyConfig; try { scriptEngine_ = createJavaScriptEngineIfPossible(this); } catch (final NoClassDefFoundError e) { scriptEngine_ = null; } // The window must be constructed AFTER the script engine. addWebWindowListener(new CurrentWindowTracker()); currentWindow_ = new TopLevelWindow("", this); fireWindowOpened(new WebWindowEvent(currentWindow_, WebWindowEvent.OPEN, null, null)); }
theClient.addWebWindowListener(new WebWindowListener() {
/** * Creates an instance that will use the specified {@link BrowserVersion} and proxy server. * @param browserVersion the browser version to simulate * @param proxyHost the server that will act as proxy or null for no proxy * @param proxyPort the port to use on the proxy server */ public WebClient(final BrowserVersion browserVersion, final String proxyHost, final int proxyPort) { WebAssert.notNull("browserVersion", browserVersion); browserVersion_ = browserVersion; if (proxyHost == null) { getOptions().setProxyConfig(new ProxyConfig()); } else { getOptions().setProxyConfig(new ProxyConfig(proxyHost, proxyPort)); } webConnection_ = new HttpWebConnection(this); // this has to be done after the browser version was set scriptEngine_ = new JavaScriptEngine(this); loadQueue_ = new ArrayList<>(); // The window must be constructed AFTER the script engine. addWebWindowListener(new CurrentWindowTracker(this)); currentWindow_ = new TopLevelWindow("", this); fireWindowOpened(new WebWindowEvent(currentWindow_, WebWindowEvent.OPEN, null, null)); if (getBrowserVersion().hasFeature(JS_XML_SUPPORT_VIA_ACTIVEXOBJECT)) { initMSXMLActiveX(); } }
/** * Creates an instance that will use the specified {@link BrowserVersion} and proxy server. * @param browserVersion the browser version to simulate * @param proxyHost the server that will act as proxy or null for no proxy * @param proxyPort the port to use on the proxy server */ public WebClient(final BrowserVersion browserVersion, final String proxyHost, final int proxyPort) { WebAssert.notNull("browserVersion", browserVersion); browserVersion_ = browserVersion; if (proxyHost == null) { getOptions().setProxyConfig(new ProxyConfig()); } else { getOptions().setProxyConfig(new ProxyConfig(proxyHost, proxyPort)); } webConnection_ = new HttpWebConnection(this); // this has to be done after the browser version was set scriptEngine_ = new JavaScriptEngine(this); loadQueue_ = new ArrayList<>(); // The window must be constructed AFTER the script engine. addWebWindowListener(new CurrentWindowTracker(this)); currentWindow_ = new TopLevelWindow("", this); fireWindowOpened(new WebWindowEvent(currentWindow_, WebWindowEvent.OPEN, null, null)); if (getBrowserVersion().hasFeature(JS_XML_SUPPORT_VIA_ACTIVEXOBJECT)) { initMSXMLActiveX(); } }
initialWindowDimension = new Dimension(currentWindow.getOuterWidth(), currentWindow.getOuterHeight()); webClient.addWebWindowListener(new WebWindowListener() { @Override public void webWindowOpened(WebWindowEvent webWindowEvent) {
wc.addWebWindowListener(new WebWindowListener() { @Override public void webWindowClosed(WebWindowEvent event) {