HttpUnit seems to only look for the "id" attribute of an HTML element when executing the getElementById javascript and doesn't recognize the "name" attribute. In a browser this method will work for both "id" and "name" attributes.
Given the following html:
contents of page1.htm:
<html>
<body onLoad="document.getElementById('field1').focus()">
<form>
field1 <input name="field1" value="Hello World" size="40"/><br>
<a href="#" onClick="alert(document.getElementById('field1').value)">This link does not work in HttpUnit</a><br>
</form>
</body>
</html>
This HttpUnit test will fail:
WebConversation wc = new WebConversation();
WebResponse resp = wc.getResponse( "http://localhost:7001/test/page1.htm" );
resp.getLinkWith("This link does not work in HttpUnit").click();
assertEquals("Hello World", wc.popNextAlert());
with the following message:
Event 'document.getElementById('field1').focus()' failed: TypeError: focus is not a function.
But if you change the "name" attribute in the INPUT control to "id":
HttpUnit seems to only look for the "id" attribute of an HTML element when executing the getElementById javascript and doesn't recognize the "name" attribute. In a browser this method will work for both "id" and "name" attributes.
Given the following html:
contents of page1.htm:
<html>
<body onLoad="document.getElementById('field1').focus()">
<form>
field1 <input name="field1" value="Hello World" size="40"/><br>
<a href="#" onClick="alert(document.getElementById('field1').value)">This link does not work in HttpUnit</a><br>
</form>
</body>
</html>
This HttpUnit test will fail:
WebConversation wc = new WebConversation();
WebResponse resp = wc.getResponse( "http://localhost:7001/test/page1.htm" );
resp.getLinkWith("This link does not work in HttpUnit").click();
assertEquals("Hello World", wc.popNextAlert());
with the following message:
Event 'document.getElementById('field1').focus()' failed: TypeError: focus is not a function.
But if you change the "name" attribute in the INPUT control to "id":
field1 <input id="field1" value="Hello World" size="40"/><br>
The same HttpUnit test passes.
I noticed that in class HTMLElementBase there is an ArrayList _supportedAttributes that contains "name". Is there somewhere else that I should look.
I would just change the "name" attributes to "id" but I have to take the code as is. I'd appreciate any thoughts you might have.
-Larry