Hi Sir,
I have a page like this:
<html>
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head></head>
<body onload="document.forms[0].submit()">
<noscript>
<p>
<strong>Note:</strong> Since your browser does not support JavaScript,
you must press the Continue button once to proceed.
</p>
</noscript>
<form action="****.com" method="post">
<noscript>
<div>
<input type="submit" value="Continue"/>
</div>
</noscript>
</form>
</body>
</html>
HtmlUnit 2.22 can not execute the onload and I can not submit the form. Is there anyway to submit the form?
Thanks.
Diff:
I changed the first two lines to be:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">And I successfully get:
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 Not Found for http://localhost:8080/****.comPlease provide your java code and revise/edit the HTML in question.
Hi Ashour,
Thanks for your quick reply. It is strange that Htmlunit can redirect in your test. My Java code is like this:
~~~
try (final WebClient webClient = (proxyconfig.getHost() == null) ? new WebClient(BrowserVersion.FIREFOX_45)
: new WebClient(BrowserVersion.FIREFOX_45, proxyconfig.getHost(), proxyconfig.getPort()))
{
webClient.getOptions().setUseInsecureSSL(true);
// try to avoid Javascript errors & Exceptions
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setPrintContentOnFailingStatusCode(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.setJavaScriptTimeout(30000);
webClient.waitForBackgroundJavaScript(3000);
webClient.getOptions().setJavaScriptEnabled(false);
currentPage = webClient.getPage(url);
}
~~~
In the currentPage, the page is the origin page(did not redirect), the value of currentPage.getBody() is HtmlBody[]. So it did not execute the onload() and did not redirect in my side. Is there any thing wrong?
Last edit: Ahmed Ashour 2016-07-14
Please remove:
I remove the code but still can not redirect automatically. The current code is :
The currentPage still remain in http://localhost:8080/DemoApp/test.jsp, and did not redirect to ****.com.
Last edit: Ahmed Ashour 2016-07-14
How can you know it didn't redirect?
Please remove all
.getOptions()setter statments, and you will have the excption thrown.I'd like to give more detailed information about my test.
I have a test.jsp deployed in tomcat, the url is http://localhost:8080/DemoApp/test.jsp, it redirect to http://localhost:8080/DemoApp/index.jsp automatically, the content is:
The java code is:
I know it did not redirect because it is still printing test.jsp, not index.jsp. In my understanding, if it redirected, the currentPage should be content of index.jsp. Then I can use forms and buttons on index.jsp.
When I remove all .getOptions(), I get the following exceptions:
Last edit: jiangchuan 2016-07-14
I retested.
Make
index.jspcontain simple text, e.g. "Hello", and you will have XML containing "Hello".The error you now see is because of something in
index.jsp, which you need to send it for further investigations, or you provide a minimal test case.Are you using my java code to do the test? It is strange that you get a different result with me.
The index.jsp is a simple page as follows:
But the result for java code System.out.println(currentPage.asXml()) is
It is not index.jsp's content.
Please try with 23-SNAPSHOT, which you can also get from here.
Code I use: