HtmlUnit ignore JavaScript errors?
Asked Answered
P

2

19

I'm trying to traverse through a website but on one of their pages I get this error:

EcmaError: lineNumber=[671] column=[0] lineSource=[null] name=[TypeError] sourceName=[https://reservations.besodelsolresort.com/asp/CalendarPopup.js] message=[TypeError: Cannot read property "parentNode" from undefined (https://reservations.besodelsolresort.com/asp/CalendarPopup.js#671)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "parentNode" from undefined (https://reservations.besodelsolresort.com/asp/CalendarPopup.js#671)

Is there anyway I can just ignore this error? I don't particularly care if the calendar loads properly.

Psaltery answered 22/1, 2014 at 21:48 Comment(1)
solution based on setting final field #8745561Tortuga
H
11

I tried to use Matthews answer and needed to override the newWebClient() method using the following way:

    HtmlUnitDriver driver = new HtmlUnitDriver(true) {
        @Override
        protected WebClient newWebClient(BrowserVersion version) {
            WebClient webClient = super.newWebClient(version);
            webClient.getOptions().setThrowExceptionOnScriptError(false);
            return webClient;
        }
    };
Histogenesis answered 10/12, 2015 at 10:41 Comment(1)
Thanks, I will delete my answer then.Aureole
C
-2

You can use the following methods of HttpUnitOptions class:

//change the scriptingEnabled flag
static void setScriptingEnabled(boolean scriptingEnabled)

// Determines whether script errors result in exceptions or warning messages.
static void setExceptionsThrownOnScriptError(boolean throwExceptions)

Or enclose the problem area in try-catch block -

try {
   // code with error

}catch(e) {
   // handle error
}
Crudity answered 22/1, 2014 at 22:35 Comment(1)
How does HttpUnit refers to HtmlUnit? Seems that these are different frameworks...Aposiopesis

© 2022 - 2024 — McMap. All rights reserved.