From: RBRi <rb...@us...> - 2018-12-03 18:37:57
|
- **status**: open --> pending - **assigned_to**: RBRi --- ** [bugs:#2003] HTMLParser.parseHtml(htmlUnitResponse, webClient.getCurrentWindow()) is not parsing the javascripts in the htmlUnitResponse.** **Status:** pending **Group:** 2.33 **Created:** Mon Dec 03, 2018 11:52 AM UTC by Manikandan Kabali **Last Updated:** Mon Dec 03, 2018 06:37 PM UTC **Owner:** RBRi Hi All, I am using htmlunit 2.33. When I pass some html string which has javascript to create dynamic DOM elements to HTMLParser.parseHtml, it is not processing the javascript in the html string. So, it is not creating the dynamic dom elements. But when i get the html page using the following piece of code it parses the js "HtmlPage page= webClient.getPage(url)". In my case, i don't want to get the page using "HtmlPage page= webClient.getPage(url)". I have the html text to be parsed. Could anyone suggest some solution to parse the js in the html string? # **sample.html** <html> <head> <title>Sample html to pdf</title> <meta charset="utf-8"/> <script type="text/javascript" src="jquery/jquery-3.3.1.js"></script> <script type="text/javascript"> jQuery( function($) { $("#dynamic").append("<p>I came via jquery!!</p>"); } ); </script> </head> <body> <div id="h1"> <center><h1>Sample HTML to PDF</h1></center> </div> <div id="dynamic"> </div> </body> </html> # java code final String rhtml = readFileAsString("D:\\Print Pdf Works\\html\\sample_html_wjs.html"); String rurl = "file:///D:/Print%20Pdf%20Works/html/sample_html_wjs.html"; URL url = new URL(rurl); StringWebResponse htmlUnitResponse = new StringWebResponse(rhtml, url); try (WebClient webClient = new WebClient()) { webClient.getOptions().setJavaScriptEnabled(true); webClient.waitForBackgroundJavaScript(90000); webClient.waitForBackgroundJavaScriptStartingBefore(90000); HtmlPage page = HTMLParser.parseHtml(htmlUnitResponse, webClient.getCurrentWindow()); System.out.println("************HTML PAGE**************"); System.out.print(page.asXml()); renderer.setDocument(page, urlString); } # output ************HTML PAGE************** <?xml version="1.0" encoding="UTF-8"?> <html> <head> <title> Sample html to pdf </title> <meta charset="utf-8"/> <script type="text/javascript" src="jquery/jquery-3.3.1.js"> </script> <script type="text/javascript"> //<![CDATA[ jQuery( function($) { $("#dynamic").append("<p>I came via jquery!!</p>"); } ); //]]> </script> </head> <body> <div id="h1"> <center> <h1> Sample HTML to PDF </h1> </center> </div> <div id="dynamic"> </div> </body> </html> --- Sent from sourceforge.net because htm...@li... is subscribed to https://sourceforge.net/p/htmlunit/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |