Reputation: 21
I'm trying to log into a site using HTMLUnit, but whenever I submit my logon details I get a massive chain of errors. I broke my code up into little pieces so I can see that it's after the submit button is clicked, but before anything else happens; it takes a while because it's a pretty slow site. Because it happens after a login I can't show you what it's meant to look like, unfortunately. I can say that a successful login has a few redirects, and because it's giving me a page not found error I'm assuming that it's one of those redirects that's causing the trouble. I have had redirect trouble with Chrome here before, although not on this particular page, and both Chrome and IE8 are loading it fine for me now.
Saving you the full stack trace, here's what appears to be the most important stuff:
SEVERE: Error loading JavaScript from [http://servicedeskmt.det.nsw.edu.au:8090/kinetic/displayPage.jsp/../resources/js/jquery/jquery-1.3.2.js].
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 /kinetic/resources/js/jquery/jquery-1.3.2.js for http://servicedeskmt.det.nsw.edu.au:8090/kinetic/resources/js/jquery/jquery-1.3.2.js
at com.gargoylesoftware.htmlunit.WebClient.throwFailingHttpStatusCodeExceptionIfNecessary(WebClient.java:535)
INFO: statusCode=[404] contentType=[text/html]
Oct 31, 2011 2:31:29 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary
INFO: <html>
<head>
<title>Page cannot be found</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div align="center">
<p> </p>
<p> </p>
<p><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">There was
an error on the page you were attempting to reach or the page could not be
found.</font></b> <br>
</p>
<p><br>
<br>
<a href="http://www.kineticdata.com"><img src="resources/poweredByKS.gif" width="131" height="45" border="0"></a>
</p>
</div>
</body>
</html>
Any advice would be greatly appreciated. Thanks.
EDIT: Adding some more detail The error occurs on loginButton.click(), whether I set the result to equal a new page or not. A line that is just loginButton.click() causes a long pause (like I say, the page takes a while to load), then throws the error. If I catch the exception and then try to load the logged-in version of the page the same thing happens, which tells me that my login attempt is successful, but loading the logged in page is causing a problem. Storing the credentials in the DefaultCredentialsProvider, then going straight to the logged in page, gives the same error. I think I can safely say it's the page, not the login.
Loading the page, and in the same statement running javascript or clicking on a button, has the same effect. I was hoping that some other part of the page wasn't loading properly but I could still fire off the bit that I wanted, but no luck.
Upvotes: 1
Views: 7029
Reputation: 330
Try one of them or all depend on what you don't want to print
Refer doc: https://htmlunit.sourceforge.io/apidocs/com/gargoylesoftware/htmlunit/WebClientOptions.html
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setPrintContentOnFailingStatusCode(false);
In my case, I got a lot error in console because webClient cannot load css, the setting below work for me:
webClient.getOptions().setCssEnabled(false);
Upvotes: 1
Reputation: 41
I don't care that it's old thread:P
If in logs you have "printContentIfNecessary" you can turn it of by setting value:
webClient.getOptions().setPrintContentOnFailingStatusCode(false);
Works good for me
Upvotes: 1
Reputation: 220
I experienced similar issue and got it working using below code:
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);
Upvotes: 5