From: asashour <asa...@ya...> - 2014-02-26 08:59:57
|
Hi Jack, - You must subscribe before posting the message (not only afterwars). - You shouldn't disable errors, as I get "com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "innerHTML" of null to "5"" - Please try to isolate a minimal test case as hinted in http://htmlunit.sourceforge.net/submittingJSBugs.html Yours, Ahmed Jack Bi wrote > Hi all: > I run the following class: > private static String urlString = "https://www.k7k6.com/"; > public static void main(String[] args) throws InterruptedException, > FailingHttpStatusCodeException, MalformedURLException, IOException { > WebClient webClient = new WebClient(BrowserVersion.CHROME); > webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); > webClient.getOptions().setThrowExceptionOnScriptError(false); > webClient.getOptions().setCssEnabled(false); > webClient.getOptions().setRedirectEnabled(true); > webClient.getOptions().setJavaScriptEnabled(true); > HtmlPage page = null; > page = webClient.getPage(urlString); > HtmlForm form = page.getForms().get(0); > HtmlTextInput textInput1 = form.getInputByName("url"); > textInput1.setValueAttribute("https://twitter.com"); > HtmlSelect seriesSelect = form.getSelectByName("server"); > > List > <HtmlOption> > optionList = seriesSelect.getOptions(); > optionList.get(2).setSelected(true); > HtmlElement button = (HtmlElement) page.createElement("button"); > button.setAttribute("type", "submit"); > form.appendChild(button); > HtmlPage page2 = null; > try { > page2 = button.click(); > } catch (IOException e) { > e.printStackTrace(); > } > Thread.sleep(30*1000); > HtmlPage page3 = > ((HtmlPage)webClient.getCurrentWindow().getEnclosedPage()); > System.out.println(page3.asXml()); > if (page3.asText().contains("Warning")) { > form = page3.getForms().get(0); > button = form.getInputByValue("Continue anyway..."); > HtmlPage page4 = button.click(); > Thread.sleep(30*1000); > > System.out.println(((HtmlPage)webClient.getCurrentWindow().getEnclosedPage()).asXml()); > }else { > System.out.println("~~~~"); > System.out.println(page3.asXml()); > } > } > ===============HTML like this================== > <html> > > <head> > > > </head> > > <body onLoad="setTimeout('delayer()', 5000)"> > > Prepare to be redirected! > > <p> > This page is a time delay redirect, please update your bookmarks to our > new > location! > </p> > > </body> > > </html> > > ================================= > I can only get a jump in the middle of the page,how can i do, so that ir > will work? > I use htmlunit 2.14 snapshot. > Thanks, > Jack. -- View this message in context: http://htmlunit.10904.n7.nabble.com/How-htmlUnit-handles-javascript-redirects-tp33235p33238.html Sent from the HtmlUnit - General mailing list archive at Nabble.com. |