Skip to content Skip to sidebar Skip to footer

Htmlunit Always Gives Multiple Javascript Exceptions After Running The Project

I'm working on a project that checks an email list that is imported to see if the user is registered or not on yahoo. When I click on the Start button, it should go to the yahoo ma

Solution 1:

The setJavaScriptEnabled(false) should be called before getting the page, otherwise the JavaScript will be executed.

So, your code should be:

    final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED);
    webClient.getOptions().setJavaScriptEnabled(false);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setRedirectEnabled(true);
    java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
    final HtmlPage page1 = webClient.getPage("https://login.yahoo.com/account/create?specId=yidReg&lang=en-JO&src=ym&done=https%3A%2F%2Fmail.yahoo.com&display=login&intl=xa");

Solution 2:

This is why HtmlUnit is not so frequently used when working with Js heavy web pages. In short, it utilizes it's own JS engine that often doesn't process JS as other real browsers do. You may read full explanation here: How to overcome an HTMLUnit ScriptException?

I'd recommend using a WebDriver for this instead.


Post a Comment for "Htmlunit Always Gives Multiple Javascript Exceptions After Running The Project"