Cannot Execute OnClick Method on a Table Cell in HttpUnit/JWebUnit

Posted on 2006-04-24
Last Modified: 2008-01-09

I'm trying to execute an onclick JS Function on a table cell using HttpUnit (and JWebUnit).  I researched the web on how to do this and all the different sites I found all said basically the same thing.  However it doesn't work for some reason.  Here's the Java code:

ScriptableDelegate delegate = getDialog().getWebTableBySummaryOrId("toolbarTable").getTableCellWithID("new").getScriptableDelegate();

and here's the HTML snippet:

<script language="javascript">
      function createNew() {
            if (document.inbox) {
      function deleteMessages() {
            var hiddenPane=document.getElementById("tab_messages__tabholder").innerHTML;
            var isSentSelected = (hiddenPane && hiddenPane.indexOf("tab_messages_sentbox") < 1);
            if (isSentSelected) {
            } else {

        function MO(e) {if (!e) var e=window.event; var S=e.srcElement; if (!S) {;} while ("TD"!=S.tagName) {S=S.parentNode;} S.className="H"; }
        function MU(e) {if (!e) var e=window.event; var S=e.srcElement; if (!S) {;} while ("TD"!=S.tagName) {S=S.parentNode;} S.className="T"; }
<table id="toolbarTable" class="toolbar">
<tr style="background-image: url(images/toolbar_bg.gif)">
   <td id="new" nowrap="true" style="width: 44px;" class="T" onmouseover="MO(event)" onmouseout="MU(event)" onclick="createNew();"><img src="images/toolbar_new.gif" border="0" style="vertical-align: text-top"><span class="TT">&nbsp;New</span></td>
   <td style="width: 5px;"> | </td>
   <td id="delete" nowrap="true" style="width: 44px;" class="T" onmouseover="MO(event)" onmouseout="MU(event)" onclick="if (confirm('Are you sure?')) deleteMessages();"><img src="images/toolbar_delete.gif" border="0" style="vertical-align: text-top"><span class="TT">&nbsp;Delete</span></td>

When I run this code:

WebTable table = getDialog().getWebTableBySummaryOrId("toolbarTable");
TableCell cell = table.getTableCellWithID("new");

it prints out "New" to the console so it appears to be getting the right table cell.  I checked to see if there was another element with an id of "new" but there isn't.  Any help would be welcome.

Question by:ECWeb

    Author Comment

    Looks like I figured out the answer to this one...same code as above with the following change.  Instead of:

    ScriptableDelegate delegate = getDialog().getWebTableBySummaryOrId("toolbarTable").getTableCellWithID("new").getScriptableDelegate();

    I do this:

    Scriptable scriptable = getDialog().getResponse().getScriptableObject();

    It works great.  I'm not sure why the other one didn't work, but oh well...

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now