Hi,
I am having problems getting the page that a form generates when clicking on a button. The form has a text field where I introduce a value, then I click on a button that shows a third button which, when clicked, opens a new window and shows a page (in AJAX I think). I set the valueAttribute of the text field and then I click on the button through htmlunit, but all I get is a blank page.
The form definition is this:
<form name=form1 method=post onSubmit="return immAlleg();">
The code of immAlleg() is:
function immAlleg() {
// Controllo targa*******************************************************************************
if (document.form1.targa.value.length>0) {
if (document.form1.targa.value.length<7) {
alert("i caratteri della targa sono almeno sette")
document.form1.targa.focus()
return false;
}
vldTargaU(false);
if (document.form1.checkTarU.value=='D') {
document.form1.action='/ARVALdoc/view/';
// document.form1.submit();
return true;
}
}
return false;
}
The button I'm clicking is this one:
<td width="34%" align=center><input type=submit onClick="nuovaFinestra()" value="visualizzazione immagini"> </td>
The code of nuovaFinestra() is:
function nuovaFinestra() {
document.form1.target="_blank";
}
So it seems that when I click the "visualizzazione immagini" button, I'm just creating a new window and right after that, the form is submitted and the new content is loaded on the newly created window. Am I right?
The new page has this function in the onload event, so maybe the fact that I'm getting a blank page is normal, but htmlunit is lacking the call to this function to generate the new page (i don't know):
<body onload="ajaxTipsPreventivi();">
and its code is:
var http;
function ajaxTipsPreventivi() {
if (window.XMLHttpRequest) { //Mozilla
http = new XMLHttpRequest();
} else if (window.ActiveXObject) { //IE
http = new ActiveXObject("Microsoft.XMLHTTP");
}
http.open('get', 'lib/getDescr.php?targa=CM869AY');
http.onreadystatechange = esegui;
http.send(null);
}
This is the Java code that I am using:
public void getPicturesMethod2(String _car) throws IOException {
HtmlPage page = (HtmlPage) webClient.getPage(("http://www.genol.net/usatodoc"));
HtmlForm form = page.getFormByName("form1");
form.getInputByName("targa").setValueAttribute(_car);
page = (HtmlPage) form.getInputByValue("visualizza dati veicolo").click();
form = page.getFormByName("form1");
page = form.getInputByValue("visualizzazione immagini").click();
page.save(new File(downloadPath+"page.html"));
}
And a couple of screendumps to see how the form looks:
First:
Second:
Any help would be appreciate! Thanks