[HtmlUnit] [htmlunit:bugs] #2003 HTMLParser.parseHtml(htmlUnitResponse, webClient.getCurrentWindow()) is not parsing the javascripts in the htmlUnitResponse.
RBRi via HtmlUnit-develop <[email protected]> Tue, 04 Dec 2018 11:27:40 -0000
| Newsgroups | gmane.comp.java.htmlunit.devel |
|---|---|
| Message-ID | </p/htmlunit/bugs/2003/3631ab672272fd1a38c5d94fdc5b0020da62fe8f.bugs@htmlunit.p.sourceforge.net> |
- **status**: pending --> closed
---
** [bugs:#2003] HTMLParser.parseHtml(htmlUnitResponse, webClient.getCurrentWindow()) is not parsing the javascripts in the htmlUnitResponse.**
**Status:** closed
**Group:** 2.33
**Created:** Mon Dec 03, 2018 11:52 AM UTC by Manikandan Kabali
**Last Updated:** Tue Dec 04, 2018 10:42 AM 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 [email protected] 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.
_______________________________________________
HtmlUnit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop