error while evaluating the functions in the script tag of an html document
naveen edupuganti <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hai
I am working on the evaluation of the functions in
the script tag of an html document and i am
encountering the fallowing erros. with the rhino part
so please help me out
here is the java code
import com.meterware.httpunit.*;
import org.w3c.dom.*;
/** This is a simple example of using HttpUnit to read
and understand web pages. **/
public class http1 {
public static void main( String[] params ) {
try {
// create the conversation object which
will maintain state for us
WebConversation wc = new
WebConversation();
// Obtain the main page on the meterware
web site
// WebRequest request = new
GetMethodWebRequest( );
WebResponse response = wc.getResponse(
"http://localhost:8080/New/test.html");
WebWindow w =wc.getMainWindow();
String response1 =
response.getLinkWith("").getURLString();
//
response.getScriptableObject().evaluateExpression("document.write('this
is anoher node ')");
wc.getCurrentPage().getScriptableObject().evaluateExpression("document.write('this
is anoher node ')");
Document doc=
wc.getCurrentPage().getDOM();
System.out.println(doc.getElementsByTagName("*").getLength());
//
wc.getCurrentPage().getDOM().appendChild(doc.createTextNode("hallo
world"));
System.out.println(wc.getCurrentPage().getText());
System.out.println(response1);
System.out.println( "The HttpUnit main
page contains " + response.getTitle()+ " links" );
System.out.println(
""+wc.popNextAlert());
System.out.println(
""+wc.popNextAlert());
System.out.println(
""+wc.popNextAlert());
//
System.out.println(wc.getCurrentPage().getText());
response.getScriptableObject().getScriptEngine().evaluateScriptExpression("function
f() { return
(doc.getElementsByTagName(\"*\").getLength()); }
function f1(x) { var k =8+x; return k*k;}function
f3() { return 'hello3'; }" );
System.out.println(response.getScriptableObject().getScriptEngine().evaluateScriptExpression("f()"));
} catch (Exception e) {
System.err.println( "Exception: " + e );
}
}
}
Here is the exception
<html>
<head>
<title>a title </title>
</head>
<script language="JavaScript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
//-->
</script>
<script>
function doit()
{
alert("hai");
}
alert("helo world");
alert("helo world1");
alert("helo world2");
alert("helo world3");
</script>
<body>
<p>text, <a href="javascript:doit();">text</a>,
...</p>
<script
type="text/javascript">document.write("<p>new
para</p>");</script>
</body>
</html>
javascript:doit();
The HttpUnit main page contains a title links
helo world
helo world1
helo world2
org.mozilla.javascript.EcmaError: ReferenceError:
"doc" is not defined.
at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3226)
at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3216)
at
org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3289)
at
org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1633)
at
org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1572)
at org.mozilla.javascript.gen.c5._c1(httpunit:0)
at org.mozilla.javascript.gen.c5.call(httpunit)
at
org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:106)
at org.mozilla.javascript.gen.c6._c0(httpunit:0)
at org.mozilla.javascript.gen.c6.call(httpunit)
at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
at
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
at org.mozilla.javascript.gen.c6.call(httpunit)
at org.mozilla.javascript.gen.c6.exec(httpunit)
at
org.mozilla.javascript.Context.evaluateString(Context.java:1132)
at
com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.evaluateScriptExpression(JavaScript.java:186)
at http1.main(http1.java:32)
Exception: com.meterware.httpunit.ScriptException: URL
'f()' failed: org.mozilla.javascript.EcmaError:
ReferenceError: "doc" is not defined.
How can i add the document to the scope of scirpting
engine.
please help me out
Thanking you
__________________________________________________________
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642