Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpUnit - call a javascript functin

807591Feb 4 2008 — edited Jun 2 2008
Hi to all,
I'm an italian student and i have some problem with HttpUnit package.
I must test a web application and i implement this java code to download a pdf file:
TableCell cell = table.getTableCell(4, 0);

WebLink link = cell.getLinks()[0];

WebResponse resp1 = link.click();
		
WebLink[] links = resp1.getLinks();
for (int i=0; i<links.length; i++){
	if (links.getText().equals("Download document")){

String strOnClick = links[i].getAttribute("onclick");
links[i].getScriptableDelegate().doEvent(strOnClick);
System.out.println(strOnClick);
}
}


With the print I have *"download('428D8B70-9xxxxxxxxx')"* , so I arrive where I want.
I want to download a pdf file from a link like this:
<a href="#" onclick="download('428D8B70-9xxxxxxxxx')">Download document</a>
The html page isn't wrote by me and i can't change it.
The error is:
com.meterware.httpunit.HttpNotFoundException: Error on HTTP request: 404 Not Found [http://localhost:7777/speed/common/docviewer?id=428D8B70-xxxxxxxxxxxxxxxxxx-xxxxx-xxx-xx-xx1&download=true]
	at org.mozilla.javascript.WrappedException.<init>(WrappedException.java:56)
	at org.mozilla.javascript.WrappedException.wrapException(WrappedException.java:111)
	at org.mozilla.javascript.ScriptableObject.setBySetter(ScriptableObject.java:296)
	at org.mozilla.javascript.ScriptableObject.put(ScriptableObject.java:256)
	at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.put(JavaScript.java:273)
	at org.mozilla.javascript.ScriptableObject.putProperty(ScriptableObject.java:1476)
	at org.mozilla.javascript.ScriptRuntime.setProp(ScriptRuntime.java:842)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2046)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2163)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:58)
	at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.performEvent(JavaScript.java:172)
	at com.meterware.httpunit.scripting.ScriptableDelegate.doEvent(ScriptableDelegate.java:56)
	at Asp_GeDoc.StartScript.search(StartScript.java:162)
	at Asp_GeDoc.Shell.main(Shell.java:36)

Exception in thread "main" java.lang.RuntimeException: Event 'download('428D8B70-xxxxxxxxxxxxxxxxx')' failed: com.meterware.httpunit.HttpNotFoundException: Error on HTTP request: 404 Not Found [http://localhost:7777/speed/common/docviewer?id=428D8B70-xxxxxxxxxxxxxxxxxx-xxxxx-xxx-xx-xx1&download=true]
	at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.handleScriptException(JavaScript.java:199)
	at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.performEvent(JavaScript.java:175)
	at com.meterware.httpunit.scripting.ScriptableDelegate.doEvent(ScriptableDelegate.java:56)
	at Asp_GeDoc.StartScript.search(StartScript.java:162)
	at Asp_GeDoc.Shell.main(Shell.java:36)
I can't use HtmlUnit.

Can anyone help me, please?

P.S.
Sorry for my english, I don't know very well :P
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 30 2008
Added on Feb 4 2008
8 comments
722 views