Hi There,
I am new to HtmlUnit and I am using this library to login/geo login with postcodes to different websites. I am able to login to websites but it is taking way too long(up to 5 mins). I need to have Javascript enabled to download the forms asyncronously.
I am using below webclient configuration
WebClient webClient = new WebClient(BrowserVersion.CHROME);
WebClientOptions webClientOption = webClient.getOptions();
webClientOption.setCssEnabled(false);
webClientOption.setJavaScriptEnabled(true);
webClientOption.setUseInsecureSSL(true);
webClientOption.setTimeout(30000);
webClientOption.setThrowExceptionOnScriptError(false);
webClientOption.setThrowExceptionOnFailingStatusCode(false);
webClientOption.setUseInsecureSSL(true);
webClientOption.setActiveXNative(true);
webClientOption.setAppletEnabled(true);
webClientOption.setPopupBlockerEnabled(false);
webClientOption.setRedirectEnabled(true);
webClient.waitForBackgroundJavaScript(30000);
webClient.waitForBackgroundJavaScriptStartingBefore(10000);
webClient.setJavaScriptTimeout(30000);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
JavaScriptEngine scriptEngine = (JavaScriptEngine) webClient.getJavaScriptEngine();
HtmlUnitContextFactory factory = scriptEngine.getContextFactory();
Context context = factory.enterContext();
context.setOptimizationLevel(9);
This is happening with almost all the website I am trying to login. Any help in improving the time to run javascript will be greatly appreciated.
Regards,
Abhishek Thakur
Without a concret URL it is a bit tricky to analyze the problem.
But two points
If you can provide a real complet sample i will have a look.
Hi There,
Thank you for coming back to me and I will use the suggestions in my application.
Also, I am trying to do two things
1. Change the country of url https://www.instacart.com/ to CA and then use the cookies for subsequent request.
My sample code will be as below
I found that without javascript enabled pages can be accessed fast but I can't change the location in the above sites as I think the location part was downloaded through some asynchronous javascript call.
Kindly suggest further on this issue as at the moment total time taken in above procedures are more than 5 mins. Thanking you in advance.
Regards,
Abhishek Thakur
Last edit: Abhishek Thakur 2019-05-30
Hi There,
When I used the above code it took me 3 mins just to load the url when JavaScript was enabled as you can see in the below logs
Altogether it took me 5 mins to update the country in the url https://www.instacart.com/ to CA! I think this is too much and HtmlUnit should be faster than that.
Regards,
Abhishek Thakur
Hi There,
I investigated further and found that without proxy it takes 4-5 secs to load a page but with proxy it takes ~30sec to load the same page. But still it takes long enough time!
Regards,
Abhishek Thakur