protected String getCurrentWindowId() { //TODO return this.currentPage.getUrl().getQuery(); }
protected String url(HtmlPage htmlPage) { return htmlPage.getUrl().toString(); } }
public String getPageURL() { if (page != null) { URL u = page.getUrl(); if (u != null) { return u.toString(); } } return null; }
@Override public void timeoutError(final HtmlPage htmlPage, final long allowedTime, final long executionTime) { logger.error("Timeout error on page {}. Allowed time: {}, execution time: {}", htmlPage.getUrl(), allowedTime, executionTime); }
@Override public void loadScriptError(final HtmlPage htmlPage, final URL scriptUrl, final Exception e) { logger.warn("Error loading script referenced on page {}. Script URL: {}, message: {}", htmlPage.getUrl(), scriptUrl, e.getMessage()); logger.debug(e.getMessage(), e); }
@Override public void malformedScriptURL(final HtmlPage htmlPage, final String url, final MalformedURLException e) { logger.error("Malformed script URL on page {}. URL: {}, message: {}", htmlPage.getUrl(), url, e.getMessage()); logger.debug(e.getMessage(), e); }
/** * Gives a basic representation for debugging purposes. * @return a basic representation */ @Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("HtmlPage("); builder.append(getUrl()); builder.append(")@"); builder.append(hashCode()); return builder.toString(); }
/** * Gives a basic representation for debugging purposes. * @return a basic representation */ @Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("HtmlPage("); builder.append(getUrl()); builder.append(")@"); builder.append(hashCode()); return builder.toString(); }
public void setPage(HtmlPage page) { assert (page != null); this.page = page; LOG.info("pageLoaded:'" + page.getTitleText() + "' " + page.getUrl()); }
@Override public void scriptException(final HtmlPage htmlPage, final ScriptException e) { logger.error("Script exception on page {}, message: {}, failing line: {}", htmlPage.getUrl(), e.getMessage(), e.getFailingLine()); logger.debug(e.getMessage(), e); }
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { final HtmlPage page = webClient.getPage("http://www.aastocks.com/en/stock/DetailQuote.aspx?&symbol1"); HtmlInput input = page.getHtmlElementById("PY_txt"); input.type("328"); final HtmlPage page2 = page.getHtmlElementById("imgHKStockSubmit").click(); System.out.println(page2.getUrl()); System.out.println(page2.asText()); }
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_9); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setRedirectEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setCssEnabled(true); HtmlPage page = (HtmlPage) webClient.getPage("http://www.sears.com/search=little tikes&Little Tikes?filter=Brand&keywordSearch=false&vName=Toys+%26+Games&catalogId=12605&catPrediction=false&previousSort=ORIGINAL_SORT_ORDER&viewItems=50&storeId=10153&adCell=W3"); WebResponse response = page.getWebResponse(); String content = response.getContentAsString(); System.out.println(page.getUrl());
/** * Adds a cookie, as long as cookies are enabled. * @see <a href="http://msdn.microsoft.com/en-us/library/ms533693.aspx">MSDN documentation</a> * @param newCookie in the format "name=value[;expires=date][;domain=domainname][;path=path][;secure] */ @JsxSetter public void setCookie(final String newCookie) { final HtmlPage page = getPage(); final WebClient client = page.getWebClient(); client.addCookie(newCookie, getPage().getUrl(), this); }
/** * Adds a cookie, as long as cookies are enabled. * @see <a href="http://msdn.microsoft.com/en-us/library/ms533693.aspx">MSDN documentation</a> * @param newCookie in the format "name=value[;expires=date][;domain=domainname][;path=path][;secure] */ @JsxSetter public void setCookie(final String newCookie) { final HtmlPage page = getPage(); final WebClient client = page.getWebClient(); client.addCookie(newCookie, getPage().getUrl(), this); }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlTextInput login = authorizationPage.getElementByName("login"); login.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput password = authorizationPage.getElementByName("passwd"); password.setValueAttribute("testpwdscribeup"); final HtmlSubmitInput submit = authorizationPage.getElementByName("SI"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput sessionUsernameOrEmail = form.getInputByName("session[username_or_email]"); sessionUsernameOrEmail.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput sessionPassword = form.getInputByName("session[password]"); sessionPassword.setValueAttribute("testpwdscribeup"); final HtmlSubmitInput submit = form.getElementById("allow"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput email = form.getInputByName("email"); email.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput password = form.getInputByName("pass"); password.setValueAttribute("testpwdscribeup"); final HtmlSubmitInput submit = form.getInputByName("login"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput login = form.getInputByName("login"); login.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput password = form.getInputByName("password"); password.setValueAttribute("testpwdscribeup1"); final HtmlSubmitInput submit = form.getInputByName("commit"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput email = form.getInputByName("Email"); email.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput passwd = form.getInputByName("Passwd"); passwd.setValueAttribute("testpwdscribeup34"); final HtmlSubmitInput submit = form.getInputByName("signIn"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getFormByName("oauthAuthorizeForm"); final HtmlTextInput sessionKey = form.getInputByName("session_key"); sessionKey.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput sessionPassword = form.getInputByName("session_password"); sessionPassword.setValueAttribute("testpwdscribeup"); final HtmlSubmitInput submit = form.getInputByName("authorize"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }