From: Jack Bi <814...@qq...> - 2014-03-15 04:54:10
|
Hi all: I found htmlUnit always failed when execute JS in html, and if I try the same code, sometimes it's success, I was puzzled for a long time. My Java code like this, hope someone can help me solve this problem,thank you very much. WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); webClient.addWebWindowListener(new WebWindowListener() { public void webWindowOpened(WebWindowEvent event) { } public void webWindowContentChanged(WebWindowEvent event) { page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage(); if (page.getTitleText().equals("Security Warning")) { warningTag = true; } if (page.asText().contains(descTag)) { finalTag = true; } } public void webWindowClosed(WebWindowEvent event) { } }); page = webClient.getPage(urlString); for(int i = 0; i < 200; i++){ if (warningTag || finalTag) { break; } Thread.sleep(1000); } the HTML code is like this: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title> title </title> <script type="text/javascript"> window.setTimeout('document.getElementById("formxh4t").submit();',1000); <form name="formxh4t" id="formxh4t" action="http://k2.ddtuangou.com/daili/process.php?action=update" method="post" onsubmit="return updateLocation(this);"> <input name="u" type="hidden" class="textbox" id="input" value="http://dongtaiwang.com" size="60"/> <input type="hidden" name="type" value="0"/> </form> </body> </html> thank you! yours jack -- View this message in context: http://htmlunit.10904.n7.nabble.com/htmlUnit-always-failed-when-execute-JS-in-html-tp33378.html Sent from the HtmlUnit - General mailing list archive at Nabble.com. |