public static void main(String[] args) throws Exception { // turn off htmlunit warnings 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); WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage("http://stackoverflow.com"); System.out.println(page.getTitleText()); }
/** * <p>Return the page title from the most recently retrieved page. * Any leading and trailing whitespace will be trimmed.</p> * * @exception Exception if an error occurs */ protected String title() throws Exception { return (page.getTitleText().trim()); }
/** * <p>Return the page title from the most recently retrieved page. * Any leading and trailing whitespace will be trimmed.</p> * * @exception Exception if an error occurs */ protected String title() throws Exception { return (page.getTitleText().trim()); }
/** * <p>Return the page title from the most recently retrieved page. * Any leading and trailing whitespace will be trimmed.</p> * * @exception Exception if an error occurs */ protected String title() throws Exception { return (page.getTitleText().trim()); }
/** * Verifies that the specified page's title equals the specified expected title. * * @param page the page to check * @param title the expected title */ public static void assertTitleEquals(final HtmlPage page, final String title) { final String s = page.getTitleText(); if (!s.equals(title)) { final String msg = "Actual page title '" + s + "' does not match expected page title '" + title + "'."; throw new AssertionError(msg); } }
/** * Verifies that the specified page's title matches the specified regular expression. * * @param page the page to check * @param regex the regular expression that the page title is expected to match */ public static void assertTitleMatches(final HtmlPage page, final String regex) { final String s = page.getTitleText(); if (!s.matches(regex)) { final String msg = "Page title '" + s + "' does not match the regular expression '" + regex + "'."; throw new AssertionError(msg); } }
/** * Verifies that the specified page's title contains the specified substring. * * @param page the page to check * @param titlePortion the substring which the page title is expected to contain */ public static void assertTitleContains(final HtmlPage page, final String titlePortion) { final String s = page.getTitleText(); if (s.indexOf(titlePortion) == -1) { final String msg = "Page title '" + s + "' does not contain the substring '" + titlePortion + "'."; throw new AssertionError(msg); } }
/** * {@inheritDoc} */ @Override public String getTitle() { return getPage().getTitleText(); }
/** * Returns this document's title. * @return this document's title */ public String jsxGet_title() { return getHtmlPage().getTitleText(); }
/** * Returns this document's title. * @return this document's title */ public String jsxGet_title() { return getHtmlPage().getTitleText(); }
/** * Returns this document's title. * @return this document's title */ public String jsxGet_title() { return getHtmlPage().getTitleText(); }
public void setPage(HtmlPage page) { assert (page != null); this.page = page; LOG.info("pageLoaded:'" + page.getTitleText() + "' " + page.getUrl()); }
try { final WebClient webClient = new WebClient(); final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net"); assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText()); } catch (Exception e) { e.printStackTrace(); }
@Test public void homePage_Firefox() throws Exception { final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17); final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net"); Assert.assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText()); webClient.closeAllWindows(); }
/** * Return the page title of the current response page, encoded as specified by the current * {@link net.sourceforge.jwebunit.util.TestContext}. */ public String getCurrentPageTitle() { if (win.getEnclosedPage() instanceof HtmlPage) { return ((HtmlPage) win.getEnclosedPage()).getTitleText(); } return ""; }
@Override public void webWindowOpened(WebWindowEvent event) { String win = event.getWebWindow().getName(); Page newPage = event.getNewPage(); if (newPage instanceof HtmlPage) { logger.debug("Window {} opened : {}", win, ((HtmlPage) newPage).getTitleText()); } else { logger.info("Window {} opened", win); } } });
public static void main(String[] args) throws IOException { java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(java.util.logging.Level.OFF); WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45); String url = "https://www.kinoheld.de/kino-muenchen/royal-filmpalast/vorstellung/280823/?mode=widget&showID=280828#panel-seats"; webClient.getOptions().setUseInsecureSSL(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.waitForBackgroundJavaScript(9000); HtmlPage response = webClient.getPage(url); System.out.println(response.getTitleText()); }
@Test public void homePage() throws Exception { final WebClient webClient = new WebClient(); final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net"); assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText()); final String pageAsXml = page.asXml(); assertTrue(pageAsXml.contains("<body class=\"composite\">")); final String pageAsText = page.asText(); assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols")); }
final HtmlPage page = webClient.getPage("http://www.google.com"); HtmlElement inputField = page.getElementByName("q"); inputField.type("Example input"); HtmlElement btnG = page.getElementByName("btnG"); Page secondPage = btnG.click(); if (secondPage instanceof HtmlPage) { System.out.println(page.getTitleText()); System.out.println(((HtmlPage)secondPage).getTitleText()); }
@Test public void homePage_proxy() throws Exception { final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_2, "http://myproxyserver", myProxyPort); //set proxy username and password final DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient.getCredentialsProvider(); credentialsProvider.addProxyCredentials("username", "password"); final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net"); assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText()); webClient.closeAllWindows(); }