protected void pickWindow() { // TODO(simon): HtmlUnit tries to track the current window as the frontmost. We don't if (currentWindow == null) { currentWindow = getWebClient().getCurrentWindow(); } }
URL url = new URL("http://www.example.com"); InputStream is = this.getClass().getClassLoader().getResourceAsStream("myPageXmlFile.xml"); String xmlPageString = IOUtils.toString(is); StringWebResponse response = new StringWebResponse(xmlPageString, url); WebClient client = WebClientConnector.createWebClient(false); // helper method for creating a WebClient instance HtmlPage page = HTMLParser.parseXHtml(response, client.getCurrentWindow());
/** * Get the latest content page returned from the server. This page may * have been changed by javascript or direct manipulation of the DOM. * * @return The Page. */ public Page getContentPage() { return webClient.getCurrentWindow().getEnclosedPage(); }
/** * Close the current window. */ @Override public void closeWindow() { if (win != null) { ((TopLevelWindow) win.getTopWindow()).close(); win = wc.getCurrentWindow(); form = null; } }
/** * Open a new window with the specified name. If the URL is non-null then attempt to load * a page from that location and put it in the new window. * * @param url the URL to load content from or null if no content is to be loaded * @param windowName the name of the new window * @return the new window */ public WebWindow openWindow(final URL url, final String windowName) { WebAssert.notNull("windowName", windowName); return openWindow(url, windowName, getCurrentWindow()); }
/** * Get the last WebResponse from HtmlUnit. */ public WebResponse getWebResponse() { return wc.getCurrentWindow().getEnclosedPage().getWebResponse(); }
/** * Open a new window with the specified name. If the URL is non-null then attempt to load * a page from that location and put it in the new window. * * @param url the URL to load content from or null if no content is to be loaded * @param windowName the name of the new window * @return the new window */ public WebWindow openWindow(final URL url, final String windowName) { WebAssert.notNull("windowName", windowName); return openWindow(url, windowName, getCurrentWindow()); }
/** * Open a new window with the specified name. If the URL is non-null then attempt to load * a page from that location and put it in the new window. * * @param url the URL to load content from or null if no content is to be loaded * @param windowName the name of the new window * @return the new window */ public WebWindow openWindow(final URL url, final String windowName) { WebAssert.notNull("windowName", windowName); return openWindow(url, windowName, getCurrentWindow()); }
/** * Open a new window with the specified name. If the URL is non-null then attempt to load * a page from that location and put it in the new window. * * @param url the URL to load content from or null if no content is to be loaded * @param windowName the name of the new window * @return the new window */ public WebWindow openWindow(final URL url, final String windowName) { WebAssert.notNull("windowName", windowName); return openWindow(url, windowName, getCurrentWindow()); }
/** * Open a new window with the specified name. If the URL is non-null then attempt to load * a page from that location and put it in the new window. * * @param url the URL to load content from or null if no content is to be loaded * @param windowName the name of the new window * @return the new window */ public WebWindow openWindow(final URL url, final String windowName) { WebAssert.notNull("windowName", windowName); return openWindow(url, windowName, getCurrentWindow()); }
@Override public InputStream getInputStream() { try { return wc.getCurrentWindow().getEnclosedPage().getWebResponse() .getContentAsStream(); } catch (IOException e) { throw new RuntimeException(e); } }
public WebDriver frame(int frameIndex) { HtmlPage page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage(); try { currentWindow = page.getFrames().get(frameIndex); } catch (IndexOutOfBoundsException e) { throw new NoSuchFrameException("Cannot find frame: " + frameIndex); } return HtmlUnitDriver.this; }
protected void pickWindow() { currentWindow = webClient.getCurrentWindow(); Page page = webClient.getCurrentWindow().getEnclosedPage(); if (page == null) return; if (!(page instanceof HtmlPage)) return; if (((HtmlPage) page).getFrames().size() > 0) { FrameWindow frame = ((HtmlPage) page).getFrames().get(0); if (!(frame.getFrameElement() instanceof HtmlInlineFrame)) switchTo().frame(0); } }
public String getWindowHandle() { WebWindow window = webClient.getCurrentWindow(); if (window.getName() == null || "".equals(window.getName())) { nameWindow(window); } return window.getName(); }
/** * Convenient method to load a URL into the current top WebWindow as it would be done * by {@link #getPage(WebWindow, WebRequestSettings)}. * @param url the URL of the new content * @param <P> the page type * @return the new page * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link #setThrowExceptionOnFailingStatusCode(boolean)} is set to true. * @throws IOException if an IO problem occurs */ @SuppressWarnings("unchecked") public <P extends Page> P getPage(final URL url) throws IOException, FailingHttpStatusCodeException { return (P) getPage(getCurrentWindow().getTopWindow(), new WebRequestSettings(url)); }
protected WebDriver findActiveWindow() { WebWindow window = webClient.getCurrentWindow(); HtmlPage page = (HtmlPage) window.getEnclosedPage(); if (page != null && page.getFrames().size() > 0) { FrameWindow frame = page.getFrames().get(0); if (!(frame.getFrameElement() instanceof HtmlInlineFrame)) return new HtmlUnitDriver(isJavascriptEnabled(), frame); } if (currentWindow != null && currentWindow.equals(window)) return this; return new HtmlUnitDriver(isJavascriptEnabled(), window); }
/** * Sets the object as active without setting focus to the object. * @see <a href="http://msdn.microsoft.com/en-us/library/ms536738.aspx">MSDN documentation</a> */ public void jsxFunction_setActive() { final Window window = getWindow(); final HTMLDocument document = window.jsxGet_document(); document.setActiveElement(this); if (window.getWebWindow() == window.getWebWindow().getWebClient().getCurrentWindow()) { final HtmlElement element = getDomNodeOrDie(); ((HtmlPage) element.getPage()).setFocusedElement(element); } }
/** * Sets the object as active without setting focus to the object. * @see <a href="http://msdn.microsoft.com/en-us/library/ms536738.aspx">MSDN documentation</a> */ public void jsxFunction_setActive() { final Window window = getWindow(); final HTMLDocument document = window.jsxGet_document(); document.setActiveElement(this); if (window.getWebWindow() == window.getWebWindow().getWebClient().getCurrentWindow()) { final HtmlElement element = getDomNodeOrDie(); ((HtmlPage) element.getPage()).setFocusedElement(element); } }
/** * Sets the object as active without setting focus to the object. * @see <a href="http://msdn.microsoft.com/en-us/library/ms536738.aspx">MSDN documentation</a> */ public void jsxFunction_setActive() { final Window window = getWindow(); final HTMLDocument document = window.jsxGet_document(); document.setActiveElement(this); if (window.getWebWindow() == window.getWebWindow().getWebClient().getCurrentWindow()) { final HtmlElement element = getDomNodeOrDie(); ((HtmlPage) element.getPage()).setFocusedElement(element); } }
/** * Sets the object as active without setting focus to the object. * @see <a href="http://msdn.microsoft.com/en-us/library/ms536738.aspx">MSDN documentation</a> */ @JsxFunction(IE) public void setActive() { final Window window = getWindow(); final HTMLDocument document = (HTMLDocument) window.getDocument(); document.setActiveElement(this); if (window.getWebWindow() == window.getWebWindow().getWebClient().getCurrentWindow()) { final HtmlElement element = getDomNodeOrDie(); ((HtmlPage) element.getPage()).setFocusedElement(element); } }