Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To ignore - Error during JavaScript execution #131

Closed
suntong opened this issue Jun 9, 2023 · 3 comments
Closed

To ignore - Error during JavaScript execution #131

suntong opened this issue Jun 9, 2023 · 3 comments

Comments

@suntong
Copy link

suntong commented Jun 9, 2023

Hope there is way to enable javascript support but ignore all its errors.

I'm getting Error during JavaScript execution on googlesyndication:

19:23:54.409 [pool-3-thread-1] ERROR org.htmlunit.javascript.DefaultJavaScriptErrorListener - Error during JavaScript execution
org.htmlunit.ScriptException: missing ) after formal parameters (https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4501446722471304#22)
        at org.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:990) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.corejs.javascript.Context.call(Context.java:590) ~[htmlunit-core-js-3.3.0.jar:?]
        at org.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:484) ~[htmlunit-core-js-3.3.0.jar:?]
        at org.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:348) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:819) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:785) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:114) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1151) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1023) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.html.ScriptElementSupport.executeScriptIfNeeded(ScriptElementSupport.java:194) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.html.ScriptElementSupport$1.execute(ScriptElementSupport.java:118) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.html.HtmlPage.initialize(HtmlPage.java:341) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.WebClient.loadWebResponseInto(WebClient.java:685) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.WebClient.loadWebResponseInto(WebClient.java:567) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.WebClient.getPage(WebClient.java:485) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.htmlunit.WebClient.getPage(WebClient.java:392) ~[htmlunit-3.3.0.jar:3.3.0]
        at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:647) ~[htmlunit3-driver-4.10.0.jar:?]
        at org.openqa.selenium.htmlunit.HtmlUnitDriver.lambda$get$7(HtmlUnitDriver.java:627) ~[htmlunit3-driver-4.10.0.jar:?]
        at org.openqa.selenium.htmlunit.HtmlUnitDriver.lambda$runAsync$0(HtmlUnitDriver.java:353) ~[htmlunit3-driver-4.10.0.jar:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:829) [?:?]

Here is the code:

    // javascript support enabled
    HtmlUnitDriver driver = new HtmlUnitDriver(true);
    driver.get("https://www.jitakong.com/jianpu/36528.html");
    WebElement elem = driver.findElement(By.cssSelector("div.entry-main > div.entry-content > figure > a"));
    System.out.println(elem.getAttribute("innerHTML"));
    driver.close();

I have to have the javascript support enabled, else won't find the designated element.
But because of the JavaScript exception, the program just aborted.

@rbri
Copy link
Collaborator

rbri commented Jun 9, 2023 via email

@suntong
Copy link
Author

suntong commented Jun 9, 2023

Thanks @rbri, I'm new to this, and am not able to find which package to import for BrowserVersion and WebClient. Would you help please?

PS. Trying to solve that problem myself while not having any IDE seems impossible.

@suntong
Copy link
Author

suntong commented Jun 9, 2023

NVM, I found them, and it works like a charm. Thanks @rbri

@suntong suntong closed this as completed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants