Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1000
  • Last Modified:

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

Hello,

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();
delegate.doEvent("onclick");

and here's the HTML snippet:

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

        function MO(e) {if (!e) var e=window.event; var S=e.srcElement; if (!S) {S=e.target;} 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) {S=e.target;} while ("TD"!=S.tagName) {S=S.parentNode;} S.className="T"; }
</script>
<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>
   <td></td>
</tr>
</table>

When I run this code:

WebTable table = getDialog().getWebTableBySummaryOrId("toolbarTable");
TableCell cell = table.getTableCellWithID("new");
System.out.println(cell.getText());

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.

Thanks!
0
ECWeb
Asked:
ECWeb
1 Solution
 
ECWebAuthor Commented:
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();
delegate.doEvent("onclick");

I do this:

Scriptable scriptable = getDialog().getResponse().getScriptableObject();
scriptable.doEvent("createNew()");

It works great.  I'm not sure why the other one didn't work, but oh well...
0
 
GranModCommented:
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now