Trying to access row/cell in a table by index fails
Pls find the ReadMe.txt inside demo.zip to run the
sample script.
Created a table with 3 rows. While trying to access
each row by index, the junit test case
fails. Have uploaded the demo.zip file to demonstrate
the problem which contains the
index.html with javascript and a junit test case
(DemoTest.java) to run the same. Place all
the necessary jar files listed in Readme.txt in lib
folder for the test case to run. Also
have attached the Readme.txt to run the TestCase.
C:>java demo.DemoTest
.Jul 24, 2006 3:52:49 PM
com.gargoylesoftware.htmlunit.javascript.host.Window
js
xFunction_alert
WARNING: window.alert("Rows len :3") no alert handler
installed
E
Time: 0.922
There was 1 error:
1) testDemo(demo.DemoTest)======= EXCEPTION START
========
EcmaError: lineNumber=[6] column=[0] lineSource=[null]
name=[TypeError] sourceNa
me=[Embedded script in file:/C:/demo/index.html]
message=[TypeError: Cannot find
default value for object. (Embedded script in
file:/C:/demo/index.html#6)]
com.gargoylesoftware.htmlunit.ScriptException:
TypeError: Cannot find default va
lue for object. (Embedded script in
file:/C:/demo/index.html#6)
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngi
ne.callFunctio
n(JavaScriptEngine.java:307)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJava
ScriptFunction
IfPossible(HtmlPage.java:733)
at
com.gargoylesoftware.htmlunit.html.ClickableElement.cli
ck(ClickableEl
ement.java:107)
at demo.DemoTest.testDemo(DemoTest.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0
(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.
java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAcces
sorImpl.java:25)
at demo.DemoTest.main(DemoTest.java:32)
Caused by: org.mozilla.javascript.EcmaError:
TypeError: Cannot find default valu
e for object. (Embedded script in
file:/C:/demo/index.html#6)
at
org.mozilla.javascript.ScriptRuntime.constructError
(ScriptRuntime.jav
a:3226)
at
org.mozilla.javascript.ScriptRuntime.constructError
(ScriptRuntime.jav
a:3216)
at
org.mozilla.javascript.ScriptRuntime.typeError
(ScriptRuntime.java:323
2)
at
org.mozilla.javascript.ScriptRuntime.typeError1
(ScriptRuntime.java:32
44)
at
org.mozilla.javascript.ScriptableObject.getDefaultValue
(ScriptableObj
ect.java:598)
at
com.gargoylesoftware.htmlunit.javascript.SimpleScriptab
le.getDefaultV
alue(SimpleScriptable.java:516)
at org.mozilla.javascript.ScriptRuntime.add
(ScriptRuntime.java:2286)
at org.mozilla.javascript.Interpreter.do_add
(Interpreter.java:4010)
at
org.mozilla.javascript.Interpreter.interpretLoop
(Interpreter.java:276
0)
at org.mozilla.javascript.Interpreter.interpret
(Interpreter.java:2250)
at
org.mozilla.javascript.InterpretedFunction.call
(InterpretedFunction.j
ava:149)
at
org.mozilla.javascript.ContextFactory.doTopCall
(ContextFactory.java:3
37)
at
org.mozilla.javascript.ScriptRuntime.doTopCall
(ScriptRuntime.java:275
5)
at
org.mozilla.javascript.InterpretedFunction.call
(InterpretedFunction.j
ava:147)
at
com.gargoylesoftware.htmlunit.javascript.host.EventHand
ler.call(Event
Handler.java:87)
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngi
ne.callFunctio
n(JavaScriptEngine.java:302)
... 20 more
Enclosed exception:
org.mozilla.javascript.EcmaError: TypeError: Cannot
find default value for objec
t. (Embedded script in file:/C:/demo/index.html#6)
at
org.mozilla.javascript.ScriptRuntime.constructError
(ScriptRuntime.jav
a:3226)
at
org.mozilla.javascript.ScriptRuntime.constructError
(ScriptRuntime.jav
a:3216)
at
org.mozilla.javascript.ScriptRuntime.typeError
(ScriptRuntime.java:323
2)
at
org.mozilla.javascript.ScriptRuntime.typeError1
(ScriptRuntime.java:32
44)
at
org.mozilla.javascript.ScriptableObject.getDefaultValue
(ScriptableObj
ect.java:598)
at
com.gargoylesoftware.htmlunit.javascript.SimpleScriptab
le.getDefaultV
alue(SimpleScriptable.java:516)
at org.mozilla.javascript.ScriptRuntime.add
(ScriptRuntime.java:2286)
at org.mozilla.javascript.Interpreter.do_add
(Interpreter.java:4010)
at
org.mozilla.javascript.Interpreter.interpretLoop
(Interpreter.java:276
0)
at script.getContent(Embedded script in
file:/C:/demo/index.html:6)
at script(event for HtmlButtonInput[<input value="Test" type="button" on="" click="javascript:getContent();" name="Test">]:1)
at org.mozilla.javascript.Interpreter.interpret
(Interpreter.java:2250)
at
org.mozilla.javascript.InterpretedFunction.call
(InterpretedFunction.j
ava:149)
at
org.mozilla.javascript.ContextFactory.doTopCall
(ContextFactory.java:3
37)
at
org.mozilla.javascript.ScriptRuntime.doTopCall
(ScriptRuntime.java:275
5)
at
org.mozilla.javascript.InterpretedFunction.call
(InterpretedFunction.j
ava:147)
at
com.gargoylesoftware.htmlunit.javascript.host.EventHand
ler.call(Event
Handler.java:87)
at
com.gargoylesoftware.htmlunit.javascript.JavaScriptEngi
ne.callFunctio
n(JavaScriptEngine.java:302)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeJava
ScriptFunction
IfPossible(HtmlPage.java:733)
at
com.gargoylesoftware.htmlunit.html.ClickableElement.cli
ck(ClickableEl
ement.java:107)
at demo.DemoTest.testDemo(DemoTest.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0
(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.
java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAcces
sorImpl.java:25)
at demo.DemoTest.main(DemoTest.java:32)
== CALLING JAVASCRIPT ==
function () {
[native code, arity=0]
}
======= EXCEPTION END ========
FAILURES!!!
Tests run: 1, Failures: 0, Errors: 1
The demo.zip contains readme file and junit test case to reproduce the issue
Logged In: YES
user_id=402164
Seems to be a string conversion problem.
The test can be simplified with:
<html>
<head>
<script>
function getContent()
{
var table = document.getElementById('data');
alert("Row 0:" + table.rows[0]);
}
</script>
</head>
<body onload="getContent()">
</body>
</html>
What should give [object HtmlTableRowElement] for FF and
something like [object] for IE. htmlunit doesn't respect
currently string conversion like browsers do (is it
important for you?) but I agree that it shouldn't cause an
expection.
Logged In: YES
user_id=402164
Now fixed in SVN.
row cell length always return zero now..Have attached the index.html
rows[index].cells.length always returns zero
Logged In: YES
user_id=402164
Please add a comment when you reopen an issue!
I've checked again and the current SVN state of htmlunit
behaves the same than FF for the 2 index.html attached to
this issue.