I have got an html page in which the UI is generated using javascript.I am interested in a form which is visible when the page is inspected using developer tools but not in html source. In htmlunit i tried to wait for the javascript to execute and then print it as Xml but DOM elements are not seen!!How can i do this??Please help
Asked
Active
Viewed 1,652 times
6
-
Pretty sure this has nothing to do with Java, but Javascript perhaps. – Stephen Lake Jan 09 '14 at 07:55
-
1possible duplicate of [Get the changed HTML content after it's updated by Javascript? (htmlunit)](http://stackoverflow.com/questions/17843521/get-the-changed-html-content-after-its-updated-by-javascript-htmlunit) – Mosty Mostacho Jan 09 '14 at 13:19
-
@MostyMostacho No it doesn't.What i get is the Javascript code not the generated html ,that is exactly my problem – joseph Jan 11 '14 at 00:17
-
@MostyMostacho Javascript doesn't change the content once the site is loaded ,and they generate some forms using Javascript and send the content to the server for validation – joseph Jan 15 '14 at 08:16
-
1In your question you say `UI is generated using javascript`. In your comment you say the opposite: `Javascript doesn't change the content once the site is loaded`. And later in your comment you say the original statement again: `they generate some forms using Javascript`. I'm not sure what to think. Anyway, the linked question should have all the information you need – Mosty Mostacho Jan 15 '14 at 13:27
-
@MostyMostacho I am Sorry what i meant was Javascript changes the content only at the loading time ,later on the page remain static no change in the page – joseph Jan 15 '14 at 13:43
-
Did you get this resolved? I am in a similar situation. – suman j Oct 02 '14 at 21:10
-
@jack No .the site i was inspecting generates a lot of forms during the loading time using javascript .the form data is sent in the post requests the page make. – joseph Oct 03 '14 at 05:37
1 Answers
1
HtmlPage.getDocumentElement().asXml()
This can be tested using
System.out.println(page.getDocumentElement().asXml());
on
<html>
<body>
<div id="lj">
</div>
<script>
document.getElementById("lj").innerHTML = "Foo";
</script>
</body>
</html>
will show
<div id="lj">
Foo
</div>

Archimedes Trajano
- 35,625
- 19
- 175
- 265